No.3747 Hamming Distance on Torus
Problem Statement
There is an $N \times N$ grid. Here, $N$ is even.
Determine whether it is possible to write either $0,1$ in each cell so that all of the following conditions are satisfied, and if it is possible, show one way to do so.
- For $i = 1,2,\ldots ,N$, the Hamming distance between the $i$-th row from the top and the $i + 1$-th row is $A$.
- For $i = 1,2,\ldots ,N$, the Hamming distance between the $i$-th column from the left and the $i + 1$-th column is $B$.
Here, the $N+1$-th row and the $N + 1$-th column refer to the $1$-st row and the $1$-st column, respectively.
There are $T$ test cases in total.
Constraints
- $1 \le T \le 1000$
- $2\le N \le 500$
- $N$ is even
- The sum of $N^2$ over all test cases is at most $250000$
- $0 \le A,B \le N$
- All input values are integers
Input
The input is given from standard input in the following format. Here, $\mathrm{case}_i$ is the $i$-th test case.
$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_T$
Each test case is given in the following format.
$N\ A\ B$
Output
Print the answers to the test cases, separated by newlines.
If it is impossible to write the digits so that the conditions are satisfied, print $-1$. Otherwise, print one such way of writing them as $N$ lines of strings $S_1,\ldots,S_N$ of length $N$ consisting of $0,1$, separated by newlines.
Here, the $j$-th character of $S_{i}$ must be the character written in the cell at the $i$-th row from the top and the $j$-th column from the left.
If there are multiple ways of writing that satisfy the conditions, any of them will be accepted.
Sample
Sample 1
Input
3 2 1 1 6 0 6 314 15 92
Output
10 00 010101 010101 010101 010101 010101 010101 -1
For the first test case, the Hamming distance between the $1$-st row and the $2$-nd row is $1$, and the Hamming distance between the $1$-st column and the $2$-nd column is also $1$. Therefore, this way of writing satisfies the conditions.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。