問題一覧 > 通常問題

No.3747 Hamming Distance on Torus

レベル : / AI推定難易度 : 2550 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 2
作問者 : Naru820 / テスター : ponjuice
お気に入りにしたユーザー ProblemId : 13948 / 自分の提出
問題文最終更新日: 2026-10-31 15:08:15
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 515 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。