Editorial for DMOPC '20 Contest 4 P2 - Beautiful Grids
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Define an odd row as a row with an odd sum, and an odd column is a column with odd sum.
For 10%, note that we need only output any valid sequence. Although many sequences can work, the simplest is to simply output
For 20%, we need only output the correct answer
Subtask 1
Let us consider only the odd rows and odd columns. Note that any flip we perform flips the parity of the relevant row and column. We can iterate through the odd rows, and choose an arbitrary odd column to flip at the same time. However, what if there are no more odd columns? Then we can simply flip an arbitrary column. We can prove that
Note that we may have some odd columns left over as well, which we can process by flipping an arbitrary row.
Time Complexity:
Subtask 2
We can optimize the solution to
Time Complexity:
Comments