Editorial for COCI '08 Contest 1 #3 Mravojed


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.

The first step is to calculate, for each cell, how many consecutive characters x there are starting with that cell, in each of the four cardinal directions.

We can recognize all cells that are corners of some square – these are cells with x in them such that at least two neighbouring squares are empty. This is important because, except in the special case when one square is completely contained in the other, each of the two squares will have at least one corner recognizable that way.

Once we have recognized a corner, we can find the size of the square: check the numbers of consecutive squares x in the two directions it extends in – the smaller of the two is the size of the square.

From the location of the corner and the size of the square, we can calculate the position of the upper-left corner. If we find only one such upper-left corner on the entire board, that means that one of the squares is inside the other so output any cell as the other square.


Comments

There are no comments at the moment.