Operations with columns and the letter L
Limits: 1 sec., 512 MiB
This statement was translated automatically from Ukrainian.
You are given a matrix \(a\) with \(n\) rows and \(m\) columns, consisting of zeros and ones.
You can perform the following operations on the matrix any number of times, possibly zero.
Choose a number \(j\) (\(1 \le j \le m\)) and invert the values of all elements in the \(j\)-th column (zeros to ones, and ones to zeros).
Choose numbers \(i\) and \(j\) (\(1 \le i \le n - 1, 1 \le j \le m - 1\)), and invert the values of three elements \(a_{i, j}, a_{i + 1, j}, a_{i, j + 1}\), which form the shape of the letter L.
Determine whether it is possible to transform \(a\) into a zero matrix using any number of operations.
Solve this problem for \(t\) matrices.
Input
The first line contains an integer \(t\) — the number of matrices for which you need to solve the problem.
The next \(t\) blocks contain the descriptions of the matrices.
The first line of each block contains two integers \(n\) and \(m\) — the number of rows and columns of the matrix.
The next \(n\) lines of the block contain the matrix consisting of zeros and ones, separated by spaces.
Output
In \(t\) lines, output the answers
for each matrix. If the matrix can be transformed into a zero matrix,
output Yes in the corresponding line, otherwise —
No.
Constraints
\(1 \le t \le 100\),
\(1 \le n, m \le 1000\),
The sum of \(n\) and \(m\) over all test cases does not exceed \(2000\),
\(a_{i, j} \in \{\verb|0|, \verb|1|\}\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 2 2 2 0 1 1 0 3 4 0 1 1 1 1 0 0 1 1 0 0 1 | No Yes |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|