#t295. 熄灯问题
熄灯问题
Lights Out
Problem Background
Special for beginners, ^_^
Problem Description
There is a matrix of buttons, with buttons in each row and 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 lamps; a button on an edge changes lamps; the other buttons change lamps.

In the figure above, the buttons marked with 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 , columns and are both pressed, so the lamp at row , column does not change state.

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:
- Pressing the same button a second time cancels the result of the first press, so each button needs to be pressed at most once;
- The order in which buttons are pressed does not affect the final result;
- 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 can be turned off. Likewise, pressing the buttons in columns can turn off the lamps in the first columns.
Input Format
rows, each containing digits ( or ), separated by single spaces. means the lamp's initial state is off, means it is on.
Output Format
rows, each containing digits ( or ), separated by single spaces. means the button was not pressed, 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.