#P12637. [UOI 2020] Golden Field

[UOI 2020] Golden Field

题目描述

Vus the Cossack accidentally found a rectangular field n×mn \times m square meters. The field has nn rows and mm columns. Rows are numbered from 11 to nn from top to bottom. Columns are numbered from 11 to mm from left to right.

Cossack noticed that in some squares there are gold coins, namely: in the square, which is in the ii-th row and the jj-th column, there are exactly aija_{ij} gold coins.

Just pick up all the coins --- it's too easy for Vus, so he decided to take all the coins from the squares where the number of coins is even.

However, this task turned out to be too easy for him, so Vus the Cossack decided to move the coins the next way: he can take all coins in a square and transfer them to any neighboring square. Squares are considered adjacent if they have a common side. He can perform the described shift operation any number of times.

Now Cossack is wondering how many coins he can take. Help him find that number, and help him understand how he needs to move coins to pick up that number.

Note that Cossack does not need to minimize the number of shift operations, he only needs to maximize the number of coins he will take.

输入格式

The first line contains two integers tt and gg (1t101 \leq t \leq 10, 0g60 \leq g \leq 6) --- number of tests and block number.

The first line of each test contains two integers nn and mm (1n,m501 \leq n, m \leq 50) --- field sizes.

Each of the next nn line contains mm integers ai1,ai2,,aima_{i1}, a_{i2}, \dots, a_{im} (0aij1000 \leq a_{ij} \leq 100) --- the number of gold coins in the squares.

It is not guaranteed that there is at least one coin in the field.

输出格式

For each test, do the following:

In the first line, print one integer --- the maximum number of coins that Vus will take.

In the second line, print one integer pp (0p100000 \leq p \leq 10\,000) --- the number of move operations that need to be performed. Note that you do not need to minimize the value of pp.

In each of the following pp lines, print four integers x1x_1, y1y_1, x2x_2, y2y_2 (1x1,x2n1 \leq x_1, x_2 \leq n, 1y1,y2m1 \leq y_1, y_2 \leq m), which means that coins that are squared (x1x_1, y1y_1) must be shifted to the square (x2x_2, y2y_2).

If there are several correct answers, it is allowed to deduce any of them. It is guaranteed that there is an optimal answer, where the number of shift operations does not exceed 1000010\,000.

2 0
2 3
4 5 1
9 2 0
1 4
1 4 5 4
20
4
1 1 2 1
1 2 2 2
2 1 2 2
2 2 2 3
14
3
1 1 1 2
1 2 1 3
1 3 1 4

提示

In the first example, the Cossack can first move all the coins from the square (1,2)(1, 2) to (2,2)(2, 2), after which the field will look like this:

$$\begin{array}{cc} 4 & 0 & 1\\ 9 & 7 & 0\\ \end{array}$$

After shifting coins from (2,2)(2, 2) to (2,1)(2, 1) the field will look like this:

$$\begin{array}{cc} 4 & 0 & 1\\ 16 & 0 & 0\\ \end{array}$$

Therefore, the answer is 4+16=204+16=20.

In the second example, the Cossack can first move all the coins from the square (1,1)(1, 1) to (1,2)(1, 2), after which the field will look like this:

0554\begin{array}{c} 0 & 5 & 5 & 4 \end{array}

After shifting coins from (1,2)(1, 2) to (1,3)(1, 3) the field will look like this:

00104\begin{array}{c} 0 & 0 & 10 & 4 \end{array}

Therefore, the answer is 10+4=1410+4=14.

Scoring

  • (1414 points) n=1n=1, all aija_{ij} are even;
  • (1616 points) n=1n=1, all aija_{ij} are odd;
  • (1919 points) n=1n=1;
  • (1414 points) n,m>1n,m>1, all aija_{ij} are even;
  • (1717 points) n,m>1n,m>1, all aija_{ij} are odd;
  • (2020 points) n,m>1n,m>1.