atcoder#ABC298B. [ABC298B] Coloring Matrix
[ABC298B] Coloring Matrix
Score : points
Problem Statement
You are given -by- matrices and where each element is or . Let and denote the element at the -th row and -th column of and , respectively. Determine whether it is possible to rotate so that for every pair of integers such that . Here, to rotate is to perform the following operation zero or more times:
- for every pair of integers such that , simultaneously replace with .
Constraints
- Each element of and is or .
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
If it is possible to rotate so that for every pair of integers such that , print Yes
; otherwise, print No
.
3
0 1 1
1 0 0
0 1 0
1 1 0
0 0 1
1 1 1
Yes
Initially, is :
0 1 1
1 0 0
0 1 0
After performing the operation once, is :
0 1 0
1 0 1
0 0 1
After performing the operation once again, is :
0 1 0
0 0 1
1 1 0
Here, for every pair of integers such that , so you should print Yes
.
2
0 0
0 0
1 1
1 1
Yes
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
No