

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 200 点
問題文
各要素が 0 あるいは 1 である N 行 N 列の行列 A, B が与えられます。
A の i 行目 j 列目の要素を A_{i,j}、B の i 行目 j 列目の要素を B_{i,j} で表します。
A を適切に回転することで、 A_{i,j} = 1 であるすべての整数の組 (i, j) について B_{i,j} = 1 が成り立っているようにできるか判定してください。
ただし、A を回転するとは、以下の操作を好きな回数(0 回でもよい)繰り返すことをいいます。
- 1 \leq i, j \leq N を満たすすべての整数の組 (i, j) について同時に A_{i,j} を A_{N + 1 - j,i} で置き換える
制約
- 1 \leq N \leq 100
- A, B の各要素は 0 か 1 のいずれか
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_{1,1} A_{1,2} \ldots A_{1,N} \vdots A_{N,1} A_{N,2} \ldots A_{N,N} B_{1,1} B_{1,2} \ldots B_{1,N} \vdots B_{N,1} B_{N,2} \ldots B_{N,N}
出力
A を適切に回転することで、A_{i,j} = 1 であるすべての整数の組 (i, j) について B_{i,j} = 1 が成り立っているようにできる場合 Yes
を、そうでない場合 No
を出力せよ。
入力例 1
3 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 1 1 1
出力例 1
Yes
はじめ、A は
0 1 1 1 0 0 0 1 0
です。
1 回操作を行うと、A は
0 1 0 1 0 1 0 0 1
となります。
もう 1 度操作を行うと、A は
0 1 0 0 0 1 1 1 0
となります。
このとき、A_{i,j} = 1 であるすべての整数の組 (i, j) について B_{i,j} = 1 が成り立っているので、Yes
を出力します。
入力例 2
2 0 0 0 0 1 1 1 1
出力例 2
Yes
入力例 3
5 0 0 1 1 0 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 1 0 1 0
出力例 3
No
Score : 200 points
Problem Statement
You are given N-by-N matrices A and B where each element is 0 or 1.
Let A_{i,j} and B_{i,j} denote the element at the i-th row and j-th column of A and B, respectively.
Determine whether it is possible to rotate A so that B_{i,j} = 1 for every pair of integers (i, j) such that A_{i,j} = 1.
Here, to rotate A is to perform the following operation zero or more times:
- for every pair of integers (i, j) such that 1 \leq i, j \leq N, simultaneously replace A_{i,j} with A_{N + 1 - j,i}.
Constraints
- 1 \leq N \leq 100
- Each element of A and B is 0 or 1.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_{1,1} A_{1,2} \ldots A_{1,N} \vdots A_{N,1} A_{N,2} \ldots A_{N,N} B_{1,1} B_{1,2} \ldots B_{1,N} \vdots B_{N,1} B_{N,2} \ldots B_{N,N}
Output
If it is possible to rotate A so that B_{i,j} = 1 for every pair of integers (i, j) such that A_{i,j} = 1, print Yes
; otherwise, print No
.
Sample Input 1
3 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 1 1 1
Sample Output 1
Yes
Initially, A is :
0 1 1 1 0 0 0 1 0
After performing the operation once, A is :
0 1 0 1 0 1 0 0 1
After performing the operation once again, A is :
0 1 0 0 0 1 1 1 0
Here, B_{i,j} = 1 for every pair of integers (i, j) such that A_{i,j} = 1, so you should print Yes
.
Sample Input 2
2 0 0 0 0 1 1 1 1
Sample Output 2
Yes
Sample Input 3
5 0 0 1 1 0 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 1 0 1 0
Sample Output 3
No