National Olympiad in Informatics, China, 2007
Our army has just obtained intercepted information that the enemy is gathering forces in preparation for an attack on our important artillery research center. Since our forces are currently deployed to multiple battles, there is no way to concentrate large numbers of soldiers for going forth and providing support. Our commanders would like to make effective deployments in order to maximize our chances of winning, while minimizing casualties and losses.
The map of the artillery research center is an
- as a military research center (denoted by the letter
O
); - as a station for a mechanized battalion (denoted by
#
); or - as open space (denoted by
.
).
Since area is limited, each
Unfortunately, due to poor pre-war estimates, the deployment of our defense department appears very scattered. This makes it very easy for the enemy's surprise attack tactics to succeed. To ensure our absolute success, our forces have decided to take advantage of the few defense battalions we have to surround all important research areas, while also moving as few steps as possible. To so-called "surround" means to ensure that enemies coming from the border of the matrix cannot find any path to a cell with a research center without also undergoing the resistance of our mechanized battalions.
Due to the communication limitations of our army, the commanders'
headquarters can only issue a command to a single battalion unit per
unit of time (to go up, down, left, or right by
Note: during the surrounding process, a unit of battalion can temporarily occupy a research area. However, battalions cannot occupy the same cell as a research area after the surrounding operation has been completed. Additionally, during any given moment, two battalions may not occupy the same cell.
Input Specification
There will be surround1.in
to surround10.in
that will be
given to your program (through standard input). They can be downloaded
here for you to study:
surround.zip.
For each of the test cases:
The first line will contain an integer between surroundi.in
will have the integer
The second line will contain two integers
The next .
, O
, or #
).
Output Specification
The first line of output should contain an integer
For the next
Sample Input
0
5 5
..##.
#...#
#OOO#
#..O#
.###.
Sample Output
1
2 1 2 2
Scoring
If your output is invalid (battalion units overlap, move out of bounds,
or the final formation does not completely surround the research
centers, etc.), then your score will be zero. Otherwise, for each test
case, if the time determined by your program is
For each test case, there are two grading parameters
Experimentation
We supply a tool surround_check.py for you to test whether your solutions are accepted. The usage for this program is:
surround_check.py <input-file> <output-file>
When you execute surround_check.py
, the program will process your
supplied input and output files and print the results to standard
output. Possible results of the execution include:
Abnormal termination
: An unknown error occurred.overlap
: Either an overlap between two battalion units occurred, or a battalion unit overlapped a research center in the final arrangement.outside
: A battalion unit moved outside of the boundaries of the matrix.move error
: Either an attempt was made to move a nonexistent battalion unit, or the distance of a move was not equal to a single unit.not surround
: Battalions did not completely surround all research centers in the final arrangement.time not match
: The number of lines in the output file did not correspond to the outputted answer.yes
: The solution is valid; submit your solution to see its score.
Problem translated to English by .
Comments