#P11543. Matrix Transformation
Matrix Transformation
Matrix Transformation
Penguin Doudou has two $01$ matrices, \(\mathbf{A}\) and \(\mathbf{B}\), of the same size. He can perform the following two types of operations on matrix \(\mathbf{A}\):
- Select a row in \(\mathbf{A}\) and flip every element in that row (i.e. change each \(0\) to \(1\) and each \(1\) to \(0\)).
- Select a column in \(\mathbf{A}\) and flip every element in that column.
The goal is to determine whether it is possible to transform \(\mathbf{A}\) into \(\mathbf{B}\) by performing a series of these operations.
In other words, using any number of row or column flips, can we obtain \(\mathbf{B}\) from \(\mathbf{A}\)?
inputFormat
The first line contains two integers \(n\) and \(m\) representing the number of rows and columns, respectively. This is followed by the description of two matrices:
- The next \(n\) lines each contain \(m\) space-separated integers (each either 0 or 1) representing the matrix \(\mathbf{A}\).
- The following \(n\) lines each contain \(m\) space-separated integers (each either 0 or 1) representing the matrix \(\mathbf{B}\).
outputFormat
Output Yes
if it is possible to transform \(\mathbf{A}\) into \(\mathbf{B}\) using the operations described above; otherwise, output No
.
sample
2 2
0 1
1 0
1 0
0 1
Yes