ICPC 2010 - F. Contour Mapping
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
Source-first archive entry
This page is built from the copied files in competitive_programming/icpc/2010/F-contour-mapping. Edit
competitive_programming/icpc/2010/F-contour-mapping/solution.tex to update the written solution and
competitive_programming/icpc/2010/F-contour-mapping/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 F
Contour Mapping
Problem ID: contour
A contour map represents the topography of a given region. Lines on a contour map represent constant
elevations. For example, a contour map might contain a line that represents points with an elevation of 100
meters above mean sea level, another line representing 200 meters elevation, and so on.
The Association for Contour Mapping (ACM) needs a program to produce contour maps from data files
containing elevation measurements collected by a satellite. They are especially interested in the total length of
all contour lines on each map. The elevation data is in the form of sequences of integers that represent elevations
measured at regular intervals along scan lines that run from west to east. The spacing of the scan lines is such
that each elevation measurement in the interior of the data set has six nearest neighbors and is equidistant from
them (when elevation is ignored), as shown in Figure 5 and Figure 6.
Figure 5 Figure 6
The policy of the ACM is to approximate the actual terrain by a set of triangles constructed by connecting each
elevation measurement to its nearest neighbors by straight line segments. Each of these triangles is then treated
as a planar surface, where the plane is determined by the coordinates, including elevation, of the vertices. If the
triangles are projected onto the zero-elevation plane, they form a set of equilateral triangles.
In the figures above, the black numbers represent elevation data and the red dashed lines and numbers represent
contour lines. Figure 5 contains a single contour line at elevation 5. Figure 6 contains multiple contour lines at
elevations 6 and 9. A contour line may pass through the interior of a triangle or run along an edge of a triangle.
Because of the way the data points are interlaced, even-numbered scan lines contain one more data point than
odd-numbered scan lines. In each figure, the first scan line is shown at the top.
Input
The input consists of several test cases, each containing a set of elevation data. Each test case begins with a line
containing four integers as follows:
• s (2 ≤ s ≤ 100) is the number of scan lines of data in the test case.
• p (1 ≤ p ≤ 100) is the number of elevation measurements on the odd numbered scan lines. The even-
numbered scan lines contain p + 1 elevation measurements.
• d (1 ≤ d ≤ 10) is the distance between each elevation measurement and its nearest neighbors when elevation
is ignored (equals the side-length of the equilateral triangles in the figures.)
• h (1 ≤ h ≤ 1000) is the elevation increment between contour lines in the desired map. The final contour map
contains a contour line wherever the elevation is an exact multiple of h. Note that a map may contain
multiple contour lines for a given elevation. Where a region is level, contour lines are shown only for the
boundaries. (See for example the contour line of elevation 9 in Figure 6.)
The first line of each test case is followed by additional lines containing elevation data as a sequence of non-
negative integers no larger than 106. The first p integers represent the elevation measurements on the first scan
line, from left to right. The next p + 1 integers represent the elevation measurements on the second scan line,
reading from left to right. The data continues in order, providing p integers for each odd-numbered scan line and
p + 1 integers for each even-numbered scan line, until all the elevation data has been provided. Each test case
ends with an empty line.
The input is terminated with a line containing a single zero.
Output
For each test case, display its case number followed by the total length of all the contour lines on the contour
map, rounded to the nearest integer. Follow the format of the sample output.
Sample Input Output for the Sample Input
3 2 5 5 Case 1: 15
1 1 Case 2: 54
1 9 1
1 1
4 4 5 3
5 7 7 5
5 9 9 9 5
9 9 9 9
7 9 9 9 7
0
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
Describe the data structures and the state maintained by the algorithm.
Explain the processing order and why it is sufficient.
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.
#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.
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}
\title{ICPC World Finals 2010\\F. Contour Mapping}
\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}
#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;
}