102981: [Atcoder]ABC298 B - Coloring Matrix

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:4 Solved:0

Description

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

Input

题意翻译

给定两个 $N\times N$ 的矩阵 $A$ 和 $B$,都由 $0$ 和 $1$ 组成。 你可以将 $A$ 顺时针旋转 $0\degree,90\degree,180\degree$ 或 $270\degree$(任选其一)。 判断旋转后的 $A$ 能否满足: - 对于每个 $A_{i,j}=1$ 的 $(i,j)$,$B_{i,j}=1$。 $1\le N\le 100$

Output

分数:$200$分

问题描述

给你一个$N$乘$N$的矩阵$A$和$B$,每个元素为0或1。
设$A_{i,j}$和$B_{i,j}$分别表示矩阵$A$和$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

执行一次操作后,$A$为:

0 1 0
1 0 1 
0 0 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

HINT

矩阵a按照制定规则旋转,是否能够实现它1的位置,矩阵b对应位置也是1?

加入题单

上一题 下一题 算法标签: