Editorial for ECOO '14 R2 P2 - Black and Grey


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

(Note from DMOJ curator: This editorial thinks the problem is called "Black and White")

First, you have to find all the factors that divide evenly into the board size, then simulate the tile flipping starting with the smallest factor and ending with the largest. But if you try to represent the entire board, you will run out of time or heap space on the larger boards. Since you only have to output the result for 5 tiles, you can avoid this by figuring out at each step whether each of the tiles should be flipped.

Suppose you are looking at the tile at row 4 and column 7 (rows and columns numbered from 0) on a 10 \times 10 board, and you are at the stage where you are using 2 \times 2 checkerboard squares. This checkerboard is 5 \times 5 and you can figure out which row and column your tile is in using integer division.

\displaystyle \begin{align*}
4 \mathbin{\text{div}} 2 &= 2 \\
7 \mathbin{\text{div}} 2 &= 3
\end{align*}

So now you know that on the 5 \times 5 checkerboard, your tile is in row 2 and column 3. Is that a black or a white checkerboard square? There are a number of ways to determine this, but one cute trick is to add up the row and column. If the result is even, the square is black. Since 2+3 = 5, the tile is in a white checkerboard square and should not be flipped on this round.


Comments

There are no comments at the moment.