CF1119C.Ramesses and Corner Inversion

普及/提高-

通过率:0%

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 AA and BB of size n×mn \times m , each of which consists of 00 and 11 only. You can apply the following operation to the matrix AA arbitrary number of times: take any submatrix of the matrix AA 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 00 , will be replaced by 11 , and all corners of the submatrix that contain 11 , will be replaced by 00 ). You have to answer whether you can obtain the matrix BB from the matrix AA .

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 MM is a matrix which consist of all elements which come from one of the rows with indices x1,x1+1,,x2x_1, x_1+1, \ldots, x_2 of matrix MM and one of the columns with indices y1,y1+1,,y2y_1, y_1+1, \ldots, y_2 of matrix MM , where x1,x2,y1,y2x_1, x_2, y_1, y_2 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)(x_1, y_1) , (x1,y2)(x_1, y_2) , (x2,y1)(x_2, y_1) , (x2,y2)(x_2, y_2) , where the cell (i,j)(i,j) denotes the cell on the intersection of the ii -th row and the jj -th column.

输入格式

The first line contains two integers nn and mm ( 1n,m5001 \leq n, m \leq 500 ) — the number of rows and the number of columns in matrices AA and BB .

Each of the next nn lines contain mm integers: the jj -th integer in the ii -th line is the jj -th element of the ii -th row of the matrix AA ( 0Aij10 \leq A_{ij} \leq 1 ).

Each of the next nn lines contain mm integers: the jj -th integer in the ii -th line is the jj -th element of the ii -th row of the matrix BB ( 0Bij10 \leq B_{ij} \leq 1 ).

输出格式

Print "Yes" (without quotes) if it is possible to transform the matrix AA to the matrix BB 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).

输入输出样例

  • 输入#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.

首页