Exercise for Leonardo
Limits: 2 sec., 512 MiB
This statement was translated automatically from Ukrainian.
Splinter has a rectangular table consisting of painted cells, where each cell has a color — black or white. Initially, all cells are black.
Splinter came up with an exercise for Leonardo: he needs to create a pattern on the table, given as a specific binary matrix of size \(n \times m\).
In one katana swing, Leonardo can repaint any rectangle of unit width or unit height into a chosen color.
More formally, he can:
choose a rectangle in the matrix such that either its width or its height is equal to \(1\);
repaint all cells of this rectangle to black or white.
To keep Leonardo on his toes, he is allowed to make no more than 3333 katana swings. Help him find any sequence of swings that will create the desired pattern and satisfy Splinter’s constraints.
Input
The first line contains two integers \(n\), \(m\).
The next \(n\) lines contain binary strings of length \(m\).
Output
In the first line, output the number of operations — \(cnt\).
In the next \(cnt\) lines, output the operations in the format \(x_1\; x_2\; y_1\; y_2\; col\).
Where \(1 \le x_1 \le x_2 \le n\) define the rows of the rectangle starting 1-based indexing from the top. And \(1 \le y_1 \le y_2 \le m\) define the columns of the rectangle starting 1-based indexing from the left.
Note that either \(x_1 = x_2\) or \(y_1 = y_2\) must hold, and \(col\) is equal to 0 or 1. The value 0 corresponds to the black color, and 1 to the white color.
Constraints
\(1 \le n, m \le 99\),
\(n\) is divisible by 3.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 3 7 0111001 0001001 0001111 | 4 1 1 2 4 1 1 3 4 4 1 3 3 4 6 1 1 3 7 7 1 |
Notes
Note that in one swing, you can repaint a rectangle of size 1 by 1.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|