CF1119C.Ramesses and Corner Inversion
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.
You are given two matrices A and B of size n×m, each of which consists of 0 and 1 only. You can apply the following operation to the matrix A arbitrary number of times: take any submatrix of the matrix A that has at least two rows and two columns, and invert the values in its corners (i.e. all corners of the submatrix that contain 0, will be replaced by 1, and all corners of the submatrix that contain 1, will be replaced by 0). You have to answer whether you can obtain the matrix B from the matrix A.
An example of the operation. The chosen submatrix is shown in blue and yellow, its corners are shown in yellow.
Ramesses don't want to perform these operations by himself, so he asks you to answer this question.
A submatrix of matrix M is a matrix which consist of all elements which come from one of the rows with indices x1,x1+1,…,x2 of matrix M and one of the columns with indices y1,y1+1,…,y2 of matrix M, where x1,x2,y1,y2 are the edge rows and columns of the submatrix. In other words, a submatrix is a set of elements of source matrix which form a solid rectangle (i.e. without holes) with sides parallel to the sides of the original matrix. The corners of the submatrix are cells (x1,y1), (x1,y2), (x2,y1), (x2,y2), where the cell (i,j) denotes the cell on the intersection of the i-th row and the j-th column.
拉美西斯来到大学参加算法训练,他的教授是一位颇有名气的程序员,给他布置了如下任务。
给定两个大小为 n×m 的矩阵 A 和 B,其中每个矩阵仅由 0 和 1 构成。你可以对矩阵 A 任意次执行以下操作:任选一个至少包含两行和两列的子矩阵,并将其四个角上的值取反(即:若某个角上是 0,则变为 1;若为 1,则变为 0)。你需要判断:能否通过若干次上述操作将矩阵 A 变为矩阵 B?
操作示意图。所选子矩阵以蓝色和黄色标出,其四个角以黄色标出。
拉美西斯不想亲自执行这些操作,因此请你回答这个问题。
矩阵 M 的一个子矩阵,是指由 M 中某连续若干行(行索引为 x1,x1+1,…,x2)与某连续若干列(列索引为 y1,y1+1,…,y2)所构成的矩阵,其中 x1,x2,y1,y2 分别为该子矩阵的边界行与边界列。换言之,子矩阵是原矩阵中一个边与原矩阵边平行的、无空洞的实心矩形区域。该子矩阵的四个角分别为单元格 (x1,y1)、(x1,y2)、(x2,y1)、(x2,y2),其中 (i,j) 表示第 i 行与第 j 列相交处的单元格。
输入格式
The first line contains two integers n and m (1≤n,m≤500) — the number of rows and the number of columns in matrices A and B.
Each of the next n lines contain m integers: the j-th integer in the i-th line is the j-th element of the i-th row of the matrix A (0≤Aij≤1).
Each of the next n lines contain m integers: the j-th integer in the i-th line is the j-th element of the i-th row of the matrix B (0≤Bij≤1).
第一行包含两个整数 n 和 m(1≤n,m≤500)—— 分别表示矩阵 A 和 B 的行数与列数。
接下来的 n 行,每行包含 m 个整数:第 i 行中的第 j 个整数为矩阵 A 第 i 行的第 j 个元素(0≤Aij≤1)。
再接下来的 n 行,每行包含 m 个整数:第 i 行中的第 j 个整数为矩阵 B 第 i 行的第 j 个元素(0≤Bij≤1)。
输出格式
Print "Yes" (without quotes) if it is possible to transform the matrix A to the matrix B using the operations described above, and "No" (without quotes), if it is not possible. You can print each letter in any case (upper or lower).
如果可以使用上述操作将矩阵 A 变换为矩阵 B,则输出 "Yes"(不带引号);否则输出 "No"(不带引号)。每个字母可使用大写或小写形式。
输入输出样例
输入#1
3 3 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 0
输出#1
Yes
输入#2
6 7 0 0 1 1 0 0 1 0 1 0 0 1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 0 0 0 1 0 0 1 0 1 0 1 0 1 0 0 1 1 1 0 1 0 1 1 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1
输出#2
Yes
输入#3
3 4 0 1 0 1 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1
输出#3
No
说明/提示
The examples are explained below.
Example 1.
Example 2.
Example 3.
示例说明如下。
示例 1。
示例 2。
示例 3。
输入解题思路,AI测评打分。不知道怎么写?