All ICPC entries
Competitive Programming

ICPC 2017 - G. Replicate Replicate Rfplicbte

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 2017
Files TeX, C++, statement assets
Folder competitive_programming/icpc/2017/G-replicate-replicate-rfplicbte
ICPC2017TeXC++statement textstatement pdf

Source-first archive entry

This page is built from the copied files in competitive_programming/icpc/2017/G-replicate-replicate-rfplicbte. Edit competitive_programming/icpc/2017/G-replicate-replicate-rfplicbte/solution.tex to update the written solution and competitive_programming/icpc/2017/G-replicate-replicate-rfplicbte/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.

Rapid City

                                                                                       event
                                                                                       sponsor
                                                                                                        ICPC 2017

                                              Problem G
                              Replicate Replicate Rfplicbte
                                         Time limit: 3 seconds
The owner of the Automatic Cellular Manufacturing corporation has just patented a new process for the
mass production of identical parts. Her approach uses a two-dimensional lattice of two-state cells, each of
which is either “empty” or “filled.” The exact details are, of course, proprietary.
Initially, a set of cells in the lattice is filled with a copy of the part that is to be reproduced. In a sequence of
discrete steps, each cell in the lattice simultaneously updates its state by examining its own state and those
of its eight surrounding neighbors. If an odd number of these nine cells are filled, the cell’s state in the next
time step will be filled, otherwise it will be empty. Figure G.1 shows several steps in the replication process
for a simple pattern consisting of three filled cells.

                                      Figure G.1: The replication process.

However, a bug has crept into the process. After each update step, one cell in the lattice might spontaneously
flip its state. For instance, Figure G.2 shows what might happen if a cell flipped its state after the first time
step and another flipped its state after the third time step.

          Figure G.2: Errors in the replication process. This figure corresponds to Sample Input 1.

Unfortunately, the original patterns were lost, and only the (possibly corrupted) results of the replication
remain. Can you write a program to determine a smallest possible nonempty initial pattern that could have
resulted in a given final pattern?

Input

The first line of input contains two integers w (1 ≤ w ≤ 300) and h (1 ≤ h ≤ 300), where w and h are
the width and height of the bounding box of the final pattern. Following that are h lines, each containing w
characters, giving the final pattern. Each character is either ‘.’ (representing an empty cell) or ‘#’ (repre-
senting a filled cell). There is at least one filled cell in the first row, in the last row, in the first column, and
in the last column.

                                                                                                   Rapid City

                                                                                 event
                                                                                 sponsor
                                                                                                ICPC 2017

Output

Display a minimum-size nonempty pattern that could have resulted in the given pattern, assuming that at
each stage of the replication process at most one cell spontaneously changed state. The size of a pattern is
the area of its bounding box. If there is more than one possible minimum-size nonempty starting pattern,
any one will be accepted. Use the character ‘.’ for empty cells and ‘#’ for filled cells. Use the minimum
number of rows and columns needed to display the pattern.

 Sample Input 1                                        Sample Output 1
 10 10                                                 .#
 .#...#...#                                            ##
 ##..##..##
 ##.#.##...
 ##.#.##...
 .#...#####
 ...##..#.#
 ......###.
 ##.#.##...
 #..#..#..#
 ##..##..##

 Sample Input 2                                        Sample Output 2
 8 8                                                   ####
 ##..#.##                                              #..#
 #.####.#                                              #.##
 .#.#.#..                                              ###.
 .##.#.##
 .#.#.#..
 .##.#.##
 #..#.###
 ##.#.##.

 Sample Input 3                                        Sample Output 3
 5 4                                                   #
 #....
 ..###
 ..###
 ..###

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/2017/G-replicate-replicate-rfplicbte/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/2017/G-replicate-replicate-rfplicbte/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 2017\\G. Replicate Replicate Rfplicbte}
\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}