#P8221. [WFOI - 02] I wanna reverse to reserve(翻转)
[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 rows and columns. It is not guaranteed that the matrix contains numbers , numbers , , numbers , but both and 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 and . The next lines each contain 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 on the next line, indicating that one solution needs operations in total. Then output lines. Each line contains one character and a number (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. 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 ), but you must ensure .
This problem uses . 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.
- : At most numbers are not in their required positions.
- : .
- : .
- : , .
All testdata satisfies , .
Translated by ChatGPT 5