No.1056 2D Lamps
Problem Statement
The time limit for this problem is 3s, and it may be difficult to solve in languages other than C++. Using scanf/printf for input and output is recommended.
There are $N^2$ lamps arranged in a grid with $N$ rows and $N$ columns.
The lamp in the $i$-th row from the top and the $j$-th column from the left is called lamp $(i,j)$.
You are given $M$ boards representing the states of the $N^2$ lamps. If $A_{i,j,k}$ is #, lamp $(j,k)$ on the $i$-th board is on, and if it is ., the lamp is off.
For every pair $i,j$ satisfying $1 \le i \lt j \le M$, determine whether the board $A_j$ can be made starting from the board $A_i$ by following the procedure below.
You may perform the following any number of times, possibly zero: choose an integer $k$, then choose and perform one of the operations below.
- For every lamp $(i,j)$ such that $i=k$, turn it off if it is on, and turn it on otherwise.
- For every lamp $(i,j)$ such that $j=k$, turn it off if it is on, and turn it on otherwise.
- For every lamp $(i,j)$ such that $i+j=k$, turn it off if it is on, and turn it on otherwise.
- For every lamp $(i,j)$ such that $i-j=k$, turn it off if it is on, and turn it on otherwise.
Input
$N\ M$
$A_{1,1,1}A_{1,1,2}A_{1,1,3}\dots A_{1,1,N}$
$A_{1,2,1}A_{1,2,2}A_{1,2,3}\dots A_{1,2,N}$
$A_{1,3,1}A_{1,3,2}A_{1,3,3}\dots A_{1,3,N}$
$\hspace{55pt} \vdots$
$A_{1,N,1}A_{1,N,2}A_{1,N,3}\dots A_{1,N,N}$
$A_{2,1,1}A_{2,1,2}A_{2,1,3}\dots A_{2,1,N}$
$A_{2,2,1}A_{2,2,2}A_{2,2,3}\dots A_{2,2,N}$
$A_{2,3,1}A_{2,3,2}A_{2,3,3}\dots A_{2,3,N}$
$\hspace{55pt} \vdots$
$A_{2,N,1}A_{2,N,2}A_{2,N,3}\dots A_{2,N,N}$
$\hspace{60pt} \vdots$
$A_{M,1,1}A_{M,1,2}A_{M,1,3}\dots A_{M,1,N}$
$A_{M,2,1}A_{M,2,2}A_{M,2,3}\dots A_{M,2,N}$
$A_{M,3,1}A_{M,3,2}A_{M,3,3}\dots A_{M,3,N}$
$\hspace{55pt} \vdots$
$A_{M,N,1}A_{M,N,2}A_{M,N,3}\dots A_{M,N,N}$
$1 \le N \le 200$
$2 \le M \le 200$
$N,M$ are integers.
$A_{i,j,k}$ is # or ..
Output
Output in the following format.
$B_{1,2}B_{1,3}B_{1,4}B_{1,5}\dots B_{1,M}$
$B_{2,3}B_{2,4}B_{2,5}\dots B_{2,M}$
$B_{3,4}B_{3,5}\dots B_{3,M}$
$\hspace{17pt} \vdots$
$B_{M - 1,M}$
$B_{i,j}$ must be 1 if the board $A_j$ can be made from the board $A_i$, and 0 otherwise.Print a newline at the end. That is, output exactly $M - 1$ newlines in total. (Added 2020/05/15 22:29)
Sample
Sample 1
Input
5 3 ..... ..... ..... ..... ..... ....# ...#. ..#.. .#... #.... #.##. #..## .#.#. ...#. .#...
Output
10 0
Board 2 can be made from board 1 by "flipping the lamps such that $i+j=6$".
Board 3 cannot be made from board 1 or from board 2, no matter what you do.
Sample 2
Input
4 6 .#.. .#.# #.## .#.# .### ##.. ###. ##.. .#.. #... .#.. ###. #..# .##. #### .#.# #.## ..#. ###. .... ##.# ##.. #.## .#..
Output
10101 0101 010 01 0
Sample 3
Input
1 2 . #
Output
1
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
QCFium
noshi91