Editorial for IOI '07 P1 - Aliens
Submitting an official solution before solving the problem yourself is a bannable offence.
We'll use the terms red cells and red squares for cells and squares with flattened grass. The other cells and squares are white. Using the alien device at some coordinates is now equivalent to checking the color of a cell.
The process of finding the solution consists of two stages. The first stage is to determine the side length  of
one square of the chessboard and the center 
 of the red square 
 containing the given red cell 
.
The second stage is to move from 
 to the center of the entire crop formation (using shifts of length 
 or
 along each coordinate).
The key part of this task is efficiently solving the first stage. In order to find , we should find:
— the rightmost x-coordinate of cells in
,
— the leftmost x-coordinate of cells in
, and
— the bottom y-coordinate of cells in
.
We describe several approaches for finding ; it is trivial to adapt them for finding 
 and 
.
The most obvious algorithm checks the colors of cells , 
, 
 etc., stopping at the
first white cell 
 and using 
 queries in the worst case. This approach would score 40 points, as
described in the 
Grading section of the task description.
To cut down on the number of queries, let's instead check the color of cells ,
stopping at the cell we call 
. This is the first white cell of the sequence or the first cell
outside the meadow boundaries (we must be careful not to query the device in the latter case). It can be shown
that all red cells left of 
 must belong to the square 
 and not to some other red square. Let 
 be the
rightmost red cell left of 
. We have used at most 
 queries so far.
Now we could reset  and repeat the procedure described in the last paragraph until 
contains only 2 cells, after which 
. However, here we have used 
queries in the worst case, which is only good enough to score 70 points.
To get the full score, use binary search on the segment  to find 
 is the only red cell in
that segment that has a neighboring white cell to the right. Using this algorithm we can find all of 
 and 
using at most 
 queries total. Now, 
.
This concludes the description of the first stage.
The second stage uses the alien device only a few times to detect which of 13 possible squares has  as the
center. Just checking the color of several cells having 
 as x-coordinates and 
 as y-coordinates will do the trick.
Comments