A control panel is an R by C grid of beacons, each off (0) or on (1). Pressing the beacon at (r, c) toggles that beacon and each of its four orthogonal neighbours (up, down, left, right) that lie inside the grid - each affected beacon flips between off and on. Apply a list of presses in order and report the final state. Rows and columns are 0-indexed.
Line 1: two integers R and C.
Next R lines: each a string of C characters, 0 or 1.
Next line: an integer P, the number of presses.
Next P lines: two integers r c, one press each.
Print R lines, each a string of C characters, the final grid.
Example 1
Input
3 3 000 000 000 1 1 1
Expected
010 111 010
Explanation
Pressing the center flips it and its four neighbours, forming a plus of ones in the middle.
Example 2
Input
2 2 11 11 2 0 0 1 1
Expected
01 10
Explanation
The two corner presses each toggle a plus; cells flipped twice return to their start, leaving 01 over 10.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →