All ICPC entries
Competitive Programming

ICPC 2013 - A. Self-Assembly

State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.

Source sync Apr 19, 2026
Track ICPC
Year 2013
Files TeX, C++, statement assets
Folder competitive_programming/icpc/2013/A-self-assembly
ICPC2013TeXC++statement textstatement pdf

Source-first archive entry

This page is built from the copied files in competitive_programming/icpc/2013/A-self-assembly. Edit competitive_programming/icpc/2013/A-self-assembly/solution.tex to update the written solution and competitive_programming/icpc/2013/A-self-assembly/solution.cpp to update the implementation.

The website does not replace those files with hand-maintained HTML. It reads the copied source tree during the build and exposes the exact files below.

Problem Statement

Copied statement text kept beside the solution archive for direct reference.

ICPC 2013
                                      2013 World Finals
                                                                                                St. Petersburg
                                                                                                 HOSTED BY   ITMO

                                           Problem A
                                         Self-Assembly
                                     Time Limit: 3 seconds
Automatic Chemical Manufacturing is experimenting with a process called self-assembly. In this pro-
cess, molecules with natural affinity for each other are mixed together in a solution and allowed to spon-
taneously assemble themselves into larger structures. But there is one problem: sometimes molecules
assemble themselves into a structure of unbounded size, which gums up the machinery.
You must write a program to decide whether a given collection of molecules can be assembled into a
structure of unbounded size. You should make two simplifying assumptions: 1) the problem is restricted
to two dimensions, and 2) each molecule in the collection is represented as a square. The four edges of
the square represent the surfaces on which the molecule can connect to other compatible molecules.
In each test case, you will be given a set of molecule descriptions. Each type of molecule is described
by four two-character connector labels that indicate how its edges can connect to the edges of other
molecules. There are two types of connector labels:

   • An uppercase letter (A, . . . , Z) followed by + or −. Two edges are compatible if their labels have
     the same letter but different signs. For example, A+ is compatible with A− but is not compatible
     with A+ or B−.

   • Two zero digits 00. An edge with this label is not compatible with any edge (not even with another
     edge labeled 00).

Assume there is an unlimited supply of molecules of each type, which may be rotated and reflected. As
the molecules assemble themselves into larger structures, the edges of two molecules may be adjacent
to each other only if they are compatible. It is permitted for an edge, regardless of its connector label, to
be connected to nothing (no adjacent molecule on that edge).
Figure A.1 shows an example of three molecule types and a structure of bounded size that can be assem-
bled from them (other bounded structures are also possible with this set of molecules).

                                Figure A.1: Illustration of Sample Input 1.

                                                                                                     ICPC 2013
                                     2013 World Finals
                                                                                                St. Petersburg
                                                                                                HOSTED BY   ITMO

Input

The input consists of a single test case. A test case consists of two lines. The first contains an integer n
(1 ≤ n ≤ 40 000) indicating the number of molecule types. The second line contains n eight-character
strings, each describing a single type of molecule, separated by single spaces. Each string consists of
four two-character connector labels representing the four edges of the molecule in clockwise order.

Output

Display the word unbounded if the set of molecule types can generate a structure of unbounded size.
Otherwise, display the word bounded.

 Sample Input 1                                        Sample Output 1
 3                                                     bounded
 A+00A+A+ 00B+D+A- B-C+00C+

 Sample Input 2                                        Sample Output 2
 1                                                     unbounded
 K+K-Q+Q-

Editorial

Rendered from the copied solution.tex file. The original TeX source remains available below.

Key Observations

  • Write the structural observations that make the problem tractable.

  • State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.

  • If the constraints matter, explain exactly which part of the solution they enable.

Algorithm

  1. Describe the data structures and the state maintained by the algorithm.

  2. Explain the processing order and why it is sufficient.

  3. Mention corner cases explicitly if they affect the implementation.

Correctness Proof

We prove that the algorithm returns the correct answer.

Lemma 1.

State the first key claim.

Proof.

Provide a concise proof.

Lemma 2.

State the next claim if needed.

Proof.

Provide a concise proof.

Theorem.

The algorithm outputs the correct answer for every valid input.

Proof.

Combine the lemmas and finish the argument.

Complexity Analysis

State the running time and memory usage in terms of the input size.

Implementation Notes

  • Mention any non-obvious implementation detail that is easy to get wrong.

  • Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.

Code

Exact copied C++ implementation from solution.cpp.

C++ competitive_programming/icpc/2013/A-self-assembly/solution.cpp

Exact copied implementation source.

Raw file
#include <bits/stdc++.h>
using namespace std;

namespace {

void solve() {
    // Fill in the full solution logic for the problem here.
}

}  // namespace

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
    return 0;
}

Source Files

Exact copied source-of-truth files. Edit solution.tex for the write-up and solution.cpp for the implementation.

TeX write-up competitive_programming/icpc/2013/A-self-assembly/solution.tex

Exact copied write-up source.

Raw file
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}

\title{ICPC World Finals 2013\\A. Self-Assembly Time Limit: 3 seconds}
\author{}
\date{}

\begin{document}
\maketitle

\section*{Problem Summary}

State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.

\section*{Key Observations}

\begin{itemize}[leftmargin=*]
    \item Write the structural observations that make the problem tractable.
    \item State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
    \item If the constraints matter, explain exactly which part of the solution they enable.
\end{itemize}

\section*{Algorithm}

\begin{enumerate}[leftmargin=*]
    \item Describe the data structures and the state maintained by the algorithm.
    \item Explain the processing order and why it is sufficient.
    \item Mention corner cases explicitly if they affect the implementation.
\end{enumerate}

\section*{Correctness Proof}

We prove that the algorithm returns the correct answer.

\paragraph{Lemma 1.}
State the first key claim.

\paragraph{Proof.}
Provide a concise proof.

\paragraph{Lemma 2.}
State the next claim if needed.

\paragraph{Proof.}
Provide a concise proof.

\paragraph{Theorem.}
The algorithm outputs the correct answer for every valid input.

\paragraph{Proof.}
Combine the lemmas and finish the argument.

\section*{Complexity Analysis}

State the running time and memory usage in terms of the input size.

\section*{Implementation Notes}

\begin{itemize}[leftmargin=*]
    \item Mention any non-obvious implementation detail that is easy to get wrong.
    \item Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
\end{itemize}

\end{document}