Editorial for IOI '18 P2 - Seats
Submitting an official solution before solving the problem yourself is a bannable offence.
Subtask 1
Determine whether a set of squares forms a rectangle or not in
Subtask 2
Let the square where the number
Here,
Check if these conditions hold from
Subtask 3
If
So it is enough to determine this condition in
This condition is determinable independently in
Subtask 4
Memorize
Subtask 5
Take
The sufficient and necessary condition of black squares forming a rectangle is that the number of pairs of adjacent two squares with different colors is two.
Manage the numbers of such pairs of squares for all values of
Subtask 6
Like above, take
Pay attention to two-times-two squares (sets of adjacent four squares.)
The sufficient and necessary condition of black squares forming a rectangle is as follows:
- There are only four two-times-two squares which contain exactly one black square.
- There are no two-times-two squares which contain exactly three black squares.
Manage the numbers of such two-times-two squares for all values of
Comments