CF1638D.Big Brush

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You found a painting on a canvas of size n×mn \times m . The canvas can be represented as a grid with nn rows and mm columns. Each cell has some color. Cell (i,j)(i, j) has color ci,jc_{i,j} .

Near the painting you also found a brush in the shape of a 2×22 \times 2 square, so the canvas was surely painted in the following way: initially, no cell was painted. Then, the following painting operation has been performed some number of times:

  • Choose two integers ii and jj ( 1i<n1 \le i < n , 1j<m1 \le j < m ) and some color kk ( 1knm1 \le k \le nm ).
  • Paint cells (i,j)(i, j) , (i+1,j)(i + 1, j) , (i,j+1)(i, j + 1) , (i+1,j+1)(i + 1, j + 1) in color kk .

All cells must be painted at least once. A cell can be painted multiple times. In this case, its final color will be the last one.

Find any sequence of at most nmnm operations that could have led to the painting you found or state that it's impossible.

输入格式

The first line of input contains two integers nn and mm ( 2n,m10002 \le n, m \le 1000 ) — the dimensions of the canvas.

On the ii -th of the next nn lines of input, there will be mm integers. The jj -th of them is ai,ja_{i,j} ( 1ai,jnm1 \le a_{i,j} \le nm ) — the color of cell (i,j)(i, j) .

输出格式

If there is no solution, print a single integer 1-1 .

Otherwise, on the first line, print one integer qq ( 1qnm1 \le q \le nm ) — the number of operations.

Next, print the operations in order. On the kk -th of the next qq lines, print three integers ii , jj , cc ( 1i<n1 \le i < n , 1j<m1 \le j < m , 1cnm1 \le c \le nm ) — the description of the kk -th operation.

If there are multiple solutions, print any.

输入输出样例

  • 输入#1

    4 4
    5 5 3 3
    1 1 5 3
    2 2 5 4
    2 2 4 4

    输出#1

    6
    1 3 3
    3 3 4
    2 2 5
    1 1 5
    2 1 1
    3 1 2
  • 输入#2

    3 4
    1 1 1 1
    2 2 3 1
    2 2 1 1

    输出#2

    -1

说明/提示

In the first test case, the solution is not unique. Here's one of them:

In the second test case, there is no way one could obtain the given painting, thus the answer is 1-1 .

首页