CF1774D.Same Count One

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

ChthollyNotaSeniorious received a special gift from AquaMoon: nn binary arrays of length mm . AquaMoon tells him that in one operation, he can choose any two arrays and any position pospos from 11 to mm , and swap the elements at positions pospos in these arrays.

He is fascinated with this game, and he wants to find the minimum number of operations needed to make the numbers of 11 s in all arrays the same. He has invited you to participate in this interesting game, so please try to find it!

If it is possible, please output specific exchange steps in the format described in the output section. Otherwise, please output 1-1 .

输入格式

The first line of the input contains a single integer tt ( 1t21041 \leq t \leq 2\cdot 10^4 ) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers nn and mm ( 2n1052 \leq n \leq 10^5 , 2m1052 \leq m \leq 10^5 ).

The ii -th of the following nn lines contains mm integers ai,1,ai,2,,ai,ma_{i, 1}, a_{i, 2}, \ldots, a_{i, m} (0ai,j1)(0 \le a_{i, j} \le 1) — the elements of the ii -th array.

It is guaranteed that the sum of nmn \cdot m over all test cases does not exceed 10610^6 .

输出格式

For each test case, if the objective is not achievable, output 1-1 .

Otherwise, in the first line output kk (0kmn)(0 \le k \le mn) — the minimum number of operations required.

The ii -th of the following kk lines should contain 33 integers, xi,yi,zix_i, y_i, z_i (1xi,yin,1zim)(1 \le x_i, y_i \le n, 1 \le z_i \le m) , which describe an operation that swap axi,zi,ayi,zia_{x_i, z_i}, a_{y_i, z_i} : swap the ziz_i -th number of the xix_i -th and yiy_i -th arrays.

输入输出样例

  • 输入#1

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

    输出#1

    1
    2 1 1
    1
    4 2 2
    -1

说明/提示

In the first test case, it's enough to do a single operation: to swap the first element in the second and the first rows. The arrays will become [0,1,1,0],[1,0,1,0],[1,0,0,1][0, 1, 1, 0], [1, 0, 1, 0], [1, 0, 0, 1] , each of them contains exactly two 11 s.

首页