ICPC 2010 - I. Robots on Ice
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/I-robots-on-ice. Edit
competitive_programming/icpc/2010/I-robots-on-ice/solution.tex to update the written solution and
competitive_programming/icpc/2010/I-robots-on-ice/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 I
Robots on Ice
Problem ID: robots
Inspired by the ice sculptures in Harbin, the members of the programming team from Arctic University of
Robotics and Automata have decided to hold their own ice festival when they return home from the contest.
They plan to harvest blocks of ice from a nearby lake when it freezes during the winter. To make it easier to
monitor the thickness of the ice, they will lay out a rectangular grid over the surface of the lake and have a light-
weight robot travel from square to square to measure ice thickness at each square in the grid. Three locations in
the grid are specified as “check-in” points and the robot is supposed to radio a progress report from these points
when it is one-fourth, one-half, and three-fourths of the way through its tour of inspection. To avoid unnecessary
wear and tear on the surface of the ice, the robot must begin its tour of the grid from the lower left corner,
designated in (row,column) coordinates as (0,0), visiting every other grid location exactly once and ending its
tour in row 0, column 1. Moreover, if there are multiple tours that the robot can follow, then a different one is to
be used each day. The robot is able to move only one square per time step in one of the four compass directions:
north, south, east, or west.
You are to design a program that determines how many different tours are possible for a given grid size and a
sequence of three check-in points. For example, suppose the lake surface is marked off in a 3 × 6 grid and that
the check-in points, in order of visitation, are (2,1), (2,4), and (0,4). Then the robot must start at (0,0) and end at
(0,1) after visiting all 18 squares. It must visit location (2,1) on step 4 (= ⎣18/4⎦), location (2,4) on step 9
(= ⎣18/2⎦), and location (0,4) on step 13 (= ⎣3×18/4⎦). There are just two ways to do this (see Figure 8). Note
that when the size of the grid is not divisible by 4, truncated division is used to determine the three check-in
times.
Figure 8
Note that some configurations may not permit any valid tours at all. For example, in a 4 × 3 grid with check-in
sequence (2,0), (3,2), and (0,2), there is no tour of the grid that begins at (0,0) and ends at (0,1).
Input
The input contains several test cases. Each test case begins with a line containing two integers m and n, where
2 ≤ m,n ≤ 8, specifying the number of rows and columns, respectively, in the grid. This is followed by a line
containing six integer values r1, c1, r2, c2, and r3, c3, where 0 ≤ ri < m and 0 ≤ ci < n for i = 1, 2, 3.
Following the last test case is a line containing two zeros.
Output
Display the case number, beginning at 1, followed by the number of possible tours that begin at row 0, column
0, end at row 0, column 1, and visit row ri, column ci at time ⎣ i × m × n / 4⎦ for i = 1, 2, 3. Follow the format of
the sample output.
Sample Input Output for the Sample Input
3 6 Case 1: 2
2 1 2 4 0 4 Case 2: 0
4 3
2 0 3 2 0 2
0 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\\I. Robots on Ice}
\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;
}