Repovive
  • Dashboard
  • Ranking
  • Submissions
  • Discussion
  1. Contests
  2. Starter Round 2
  3. 10E

My submissions

/
/
/
/

Announcements

My submissions

/
/
/
/

Announcements

Solve
Author

10E. L-Toggle Table

2500 pts·1s·256 MB

Constraints

Input

Output

Samples

Input
2 3
101
010
Explanation

Each operation toggles one valid L-shaped tile. After all listed operations, the whole table becomes zero.

Output
3
1 2 2
2 2 3
2 3 4
Input
3 3
010
101
010
Explanation
Output
2
2 2 1
2 2 4

You are given a binary table with nnn rows and mmm columns.

In one operation, you choose one L-shaped tile and toggle all cells covered by it.
Toggling a cell means changing 000 to 111 and changing 111 to 000.

Each tile covers exactly three cells. The tile is described by the coordinate of its center cell and one of the following four types.

If the center is (x,y)(x,y)(x,y):

TypeCovered cells
111(x,y)(x,y)(x,y), (x+1,y)(x+1,y)(x+1,y), (x,y+1)(x,y+1)(x,y+1)
222(x,y)(x,y)(x,y), (x+1,y)(x+1,y)(x+1,y), (x,y−1)(x,y-1)(x,y−1)
333(x,y)(x,y)(x,y), (x−1,y)(x-1,y)(x−1,y), (x,y+1)(x,y+1)(x,y+1)
444(x,y)(x,y)(x,y), (x−1,y)(x-1,y)(x−1,y), (x,y−1)(x,y-1)(x,y−1)

All covered cells must be inside the table.

Your task is to make all cells equal to 000 using at most 4nm4nm4nm operations.

It can be proven that under the given constraints, such a sequence of operations always exists.

  • 2≤n,m≤1002 \le n,m \le 1002≤n,m≤100
  • Each cell of the table is either 000 or 111
nms1s2⋮sn\begin{array}{l} n \quad m \\ s_1 \\ s_2 \\ \vdots \\ s_n \end{array}nms1​s2​⋮sn​​

Here sis_isi​ is a binary string of length mmm, describing row iii of the table.

First, output an integer kkk, the number of operations.

Then output kkk lines. Each line must contain three integers xxx, yyy, and ppp, meaning that you apply a tile with center (x,y)(x,y)(x,y) and type ppp.

For every operation, the following must hold:

  • 1≤x≤n1 \le x \le n1≤x≤n
  • 1≤y≤m1 \le y \le m1≤y≤m
  • 1≤p≤41 \le p \le 41≤p≤4

Also, all cells covered by the chosen tile must be inside the table.

kxyp}×k\begin{array}{l} k \\ \left. \begin{array}{l} x \quad y \quad p \end{array} \right\} \times k \end{array}kxyp​}×k​

Your output must satisfy 0≤k≤4nm0 \le k \le 4nm0≤k≤4nm.

If there are multiple valid answers, you may output any of them.

Initially, the table is:

010101010\begin{array}{ccc} 0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0 \end{array}010​101​010​

After applying operation (2,2,1)(2,2,1)(2,2,1), cells (2,2)(2,2)(2,2), (3,2)(3,2)(3,2), and (2,3)(2,3)(2,3) are toggled. The table becomes:

010110000\begin{array}{ccc} 0 & 1 & 0 \\ 1 & 1 & 0 \\ 0 & 0 & 0 \end{array}010​110​000​

After applying operation (2,2,4)(2,2,4)(2,2,4), cells (2,2)(2,2)(2,2), (1,2)(1,2)(1,2), and (2,1)(2,1)(2,1) are toggled. The table becomes:

000000000\begin{array}{ccc} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{array}000​000​000​

So the output is valid.