#P8221. [WFOI - 02] I wanna reverse to reserve(翻转)

    ID: 9171 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>洛谷原创Special JudgeO2优化构造洛谷月赛

[WFOI - 02] I wanna reverse to reserve(翻转)

Background

A gentleman is not a mere tool.

“I am best at solving puzzles, right, kid?”

“Hmm...”

Problem Description

Kid walks into a matrix with nn rows and mm columns. It is not guaranteed that the matrix contains nn numbers 11, nn numbers 22, \dots , nn numbers mm, but both nn and mm are even numbers.

There are two ways to change the matrix:

  • Choose any row and reverse (flip) the numbers in this row.
  • Choose any column and reverse (flip) the numbers in this column.

In each operation, you may choose either way.

Now you need to perform several operations to turn the matrix into:

$$n\;行\left\{ \begin{array}{l} 1\quad2\quad3\quad\cdots\quad m\\ \\ 1\quad2\quad3\quad\cdots\quad m\\ \\ \cdots\\ \\ 1\quad2\quad3\quad\cdots\quad m\\ \end{array} \right.$$

Only then will the next save point appear.

You need to help kid solve this problem.

You only need to output an answer; leave the remaining operations to Uvocde!

Input Format

The first line contains two positive integers nn and mm. The next nn lines each contain mm positive integers, describing the matrix.

Output Format

The first line contains one string. If it is impossible to find a feasible sequence of operations, output NO; otherwise output YES.

If you output YES, output a non-negative integer ansans on the next line, indicating that one solution needs ansans operations in total. Then output ansans lines. Each line contains one character and a number kk (separated by a space). The character indicates whether this operation flips a row or a column: 0 means flipping a row, and 1 means flipping a column. kk indicates which row or which column to flip.

If a feasible solution exists, you only need to output one feasible solution (you do not need to minimize ansans), but you must ensure ansn×mans \le n \times m.

This problem uses SPJ\text{SPJ}. As long as the flip operations are correct, you will get the score.

2 4
1 2 3 4
4 3 2 1
YES
1
0 2
2 4
1 2 3 4
4 1 3 2
NO

Hint

Constraints

This problem uses bundled Subtasks.

  • Subtask #0 (20pts)\texttt{Subtask \#0 (20pts)}: At most 22 numbers are not in their required positions.
  • Subtask #1 (20pts)\texttt{Subtask \#1 (20pts)}: n=2n=2.
  • Subtask #2 (20pts)\texttt{Subtask \#2 (20pts)}: m=2m=2.
  • Subtask #3 (40pts)\texttt{Subtask \#3 (40pts)}: 1n1001\le n\le 100, 1m1001\le m\le 100.

All testdata satisfies 1n1001\le n\le 100, 1m1001\le m\le 100.

Translated by ChatGPT 5