#t295. 熄灯问题

熄灯问题

Lights Out

Problem Background

Special for beginners, ^_^

Problem Description

There is a matrix of buttons, with 66 buttons in each row and 55 rows in total. At the position of each button there is a lamp. When a button is pressed, that button and its neighbours (above, below, left, right) toggle their state once: if a lamp was on it turns off, and if it was off it turns on. A button at a corner changes 33 lamps; a button on an edge changes 44 lamps; the other buttons change 55 lamps.

pic1.png

In the figure above, the buttons marked with XX are the ones pressed; the right matrix shows how the lamp states changed. When several neighbouring buttons of a lamp are all pressed, one operation cancels another. In the figure below, the buttons in row 22, columns 33 and 55 are both pressed, so the lamp at row 22, column 44 does not change state.

pic2.png

Write a program that determines which buttons must be pressed so that exactly all the lamps are turned off. From the rules above we know:

  1. Pressing the same button a second time cancels the result of the first press, so each button needs to be pressed at most once;
  2. The order in which buttons are pressed does not affect the final result;
  3. For each lit lamp in the first row, pressing the corresponding button in the second row turns off all the lamps in the first row.

Repeating this way, all lamps in rows 1,2,3,41, 2, 3, 4 can be turned off. Likewise, pressing the buttons in columns 1,2,3,4,51, 2, 3, 4, 5 can turn off the lamps in the first 55 columns.

Input Format

55 rows, each containing 66 digits (00 or 11), separated by single spaces. 00 means the lamp's initial state is off, 11 means it is on.

Output Format

55 rows, each containing 66 digits (00 or 11), separated by single spaces. 00 means the button was not pressed, 11 means it was pressed.

Sample Input

0 1 1 0 1 0
1 0 0 1 1 1
0 0 1 0 0 1
1 0 0 1 0 1
0 1 1 1 0 0

Sample Output

1 0 1 0 0 1
1 1 0 1 0 1
0 0 1 0 1 1
1 0 0 1 0 0
0 1 0 0 0 0

Constraints

Time limit: 1s, memory limit: 1024KiB for each test case.