Editorial for ECOO '14 R2 P2 - Black and Grey
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 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 and column (rows and columns numbered from ) on a board, and you are at the stage where you are using checkerboard squares. This checkerboard is and you can figure out which row and column your tile is in using integer division.
So now you know that on the checkerboard, your tile is in row and column . 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 , the tile is in a white checkerboard square and should not be flipped on this round.
Comments