Time limit
2s
Memory limit
128 MB
Chulsoo has a lighting fixture whose lamps are arranged in an N × M grid. Each lamp is either red or white. As the lighting director, Chulsoo can change the fixture with the following two kinds of buttons.
For example, suppose the fixture is the 4 × 5 grid shown in (a) below. 0 means white and 1 means red. If the second row button is pressed in (a), the fixture becomes (b). If the second and fourth column buttons are then pressed together, those columns are swapped and the fixture becomes (c).
| ``` | ||
| 01001 | ||
| 10110 | ||
| 01110 | ||
| 10101 | ||
| ``` | ``` | |
| 01001 | ||
| 01001 | ||
| 01110 | ||
| 10111 | ||
| ``` | ``` | |
| 00011 | ||
| 00011 | ||
| 01110 | ||
| 11101 |
| (a) | (b) | (c) |
Given the initial colors and the target colors of an N × M lighting fixture, find an order of row-button and column-button operations that transforms the initial state into the target state.The first line contains two integers N and M, the number of rows and columns of the lighting fixture.
The next N lines describe the initial state. Each line contains M values for the colors in that row.
The following N lines describe the target state in the same format.
Each value is either 0 or 1. 0 means white, and 1 means red.
If the initial state cannot be transformed into the target state, print -1 on the first line.
Otherwise, print the number of operations S on the first line. S is the sum of R, the number of row-button presses, and C, the number of column swaps.
Then print S lines, one for each operation in the order they are performed.
0 i.1 i j.The same row button may be pressed at most twice, and the same pair of column buttons may also be pressed at most twice.
| (a) | (b) | (c) |
Given the initial colors and the target colors of an N × M lighting fixture, find an order of row-button and column-button operations that transforms the initial state into the target state.