All ICPC entries
Competitive Programming

ICPC 2011 - C. Ancient Messages

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 2011
Files TeX, C++, statement assets
Folder competitive_programming/icpc/2011/C-ancient-messages
ICPC2011TeXC++statement textstatement pdf

Source-first archive entry

This page is built from the copied files in competitive_programming/icpc/2011/C-ancient-messages. Edit competitive_programming/icpc/2011/C-ancient-messages/solution.tex to update the written solution and competitive_programming/icpc/2011/C-ancient-messages/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.

Problem C
                                                    Ancient Messages
                                                       Problem ID: ancient
In order to understand early civilizations, archaeologists often study texts written in ancient languages. One such
language, used in Egypt more than 3000 years ago, is based on characters called hieroglyphs. Figure C.1 shows six
hieroglyphs and their names. In this problem, you will write a program to recognize these six characters.

                Ankh                 Wedjat                    Djed                 Scarab                 Was            Akeht

                                                         Figure C.1: Six hieroglyphs

Input

The input consists of several test cases, each of which describes an image containing one or more hieroglyphs chosen
from among those shown in Figure C.1. The image is given in the form of a series of horizontal scan lines consisting
of black pixels (represented by 1) and white pixels (represented by 0). In the input data, each scan line is encoded
in hexadecimal notation. For example, the sequence of eight pixels 10011100 (one black pixel, followed by two
white pixels, and so on) would be represented in hexadecimal notation as 9c. Only digits and lowercase letters a
through f are used in the hexadecimal encoding. The first line of each test case contains two integers, H and W. H
(0 < H ≤ 200) is the number of scan lines in the image. W (0 < W ≤ 50) is the number of hexadecimal characters
in each line. The next H lines contain the hexadecimal characters of the image, working from top to bottom. Input
images conform to the following rules:

   • The image contains only hieroglyphs shown in Figure C.1.
   • Each image contains at least one valid hieroglyph.
   • Each black pixel in the image is part of a valid hieroglyph.
   • Each hieroglyph consists of a connected set of black pixels and each black pixel has at least one other black
     pixel on its top, bottom, left, or right side.
   • The hieroglyphs do not touch and no hieroglyph is inside another hieroglyph.
   • Two black pixels that touch diagonally will always have a common touching black pixel.
   • The hieroglyphs may be distorted but each has a shape that is topologically equivalent to one of the symbols in
     Figure C.11 .

The last test case is followed by a line containing two zeros.

  1 Two   figures are topologically equivalent if each can be transformed into the other by stretching without tearing.

ICPC 2011 World Finals Problem C: Ancient Messages

Output

For each test case, display its case number followed by a string containing one character for each hieroglyph recognized
in the image, using the following code:

      Ankh: A
      Wedjat: J
      Djed: D
      Scarab: S
      Was: W
      Akhet: K

In each output string, print the codes in alphabetic order. Follow the format of the sample output.
The sample input contains descriptions of test cases shown in Figures C.2 and C.3. Due to space constraints not all of
the sample input can be shown on this page.

                    Figure C.2: AKW                                                Figure C.3: AAAAA

  Sample input                                                         Output for the Sample Input
  100 25                                                               Case 1: AKW
  0000000000000000000000000                                            Case 2: AAAAA
  0000000000000000000000000
   ...(50 lines omitted)...
  00001fe0000000000007c0000
  00003fe0000000000007c0000
   ...(44 lines omitted)...
  0000000000000000000000000
  0000000000000000000000000
  150 38
  00000000000000000000000000000000000000
  00000000000000000000000000000000000000
      ...(75 lines omitted)...
  0000000003fffffffffffffffff00000000000
  0000000003fffffffffffffffff00000000000
      ...(69 lines omitted)...
  00000000000000000000000000000000000000
  00000000000000000000000000000000000000
  0 0

ICPC 2011 World Finals Problem C: Ancient Messages

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/2011/C-ancient-messages/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/2011/C-ancient-messages/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 2011\\C. Ancient Messages}
\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}