Editorial for COCI '08 Contest 4 #4 Slikar
Submitting an official solution before solving the problem yourself is a bannable offence.
The solution calculates three numbers for every square : the difference if we colour all white, the difference if we colour all black, and the difference if we recursively use the procedure from the problem statement (dividing into four sub-squares) on .
To calculate this last number, we use dynamic programming. First separate into four sub-squares and calculate all three numbers for each of the sub-squares. From the calculated numbers for sub-squares, it is trivial to calculate the first and second numbers for . The third is calculated by considering all ways of choosing which sub-square is coloured white, which one is coloured black and which two we apply the recursive algorithm on. There are a couple of ways to do this and we will of course choose the one that minimizes the overall difference.
Comments