Matrix Transformation
Time limit1sMemory limit128 MB
Decide whether repeated plus-or-minus-one updates on adjacent cell pairs can turn each matrix into all zeros.
Problem
You have an integer matrix with rows and columns, so each of the rows holds integers.
Two integers are adjacent when the cells holding them share an edge. For example, in the grid below
0 1 2
3 4 5
6 7 8
, , , are adjacent, but , , are not.
Only one kind of operation is allowed on the matrix. In one step you select two adjacent cells and either increase both values by 1 or decrease both values by 1. Given a matrix, determine whether repeating this operation can turn it into a zero matrix. A zero matrix is one whose every entry is 0.
Input
The first line contains a positive integer , the number of matrices.
Each matrix starts with a line holding () and () separated by a single space. Each of the next lines contains integers. Every one of these integers is between and inclusive.
Each input matrix has at least one non-zero value.
Output
For each matrix print YES on its own line if it can be turned into a zero matrix, and NO otherwise. Use capital letters only.