問題一覧 > 通常問題

No.1851 Regular Tiling

レベル : / AI推定難易度 : 1300 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 71
作問者 : 蜜蜂 / テスター : Mitarushi
お気に入りにしたユーザー ProblemId : 6123 / 自分の提出
問題文最終更新日: 2022-02-26 00:08:30
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 333 (灘高入試コンテスト2022) (順位表) の他の問題:

Problem Statement

There is a grid with $H$ rows and $W$ columns.
You want to write an integer between $0$ and $77$, inclusive, in each cell. Exactly $1$ integer is written in each cell. The following condition must be satisfied.

  • For every cell, the number written in that cell is equal to the number of cells that are adjacent to that cell vertically or horizontally and have the same number written in them.

Determine whether there is a way to write numbers that satisfies the condition, and if there is, output one example.

You are given $T$ test cases; solve each of them.

Input

Line $1$ of the input is as follows.
$T$
Then, $T$ test cases follow. Each of them is given in the following format.
$H\ \ W$

  • $1 \leq T \leq 100$
  • $1 \leq H,W \leq 100$
  • All inputs are integers.

Output

If there is no way to write numbers that satisfies the condition, output -1 followed by a newline.

Otherwise, output as follows.

$G_{1,1}\ \ G_{1,2}\ \ \cdots G_{1,W}$
$G_{2,1}\ \ G_{2,2}\ \ \cdots G_{2,W}$
$\vdots$
$G_{H,1}\ \ G_{H,2}\ \ \cdots G_{H,W}$

Here, $G_{i,j}$ denotes the number written in the cell at row $i$, column $j$.

Do this for all $T$ test cases.

Sample

Sample 1
Input
2
3 3
1 1
Output
2 2 2
2 0 2
2 2 2
0

Consider test case $1$. For example, the number written in the cell at row $1$, column $1$ is $2$.

The cells adjacent to this cell vertically or horizontally are the cell at row $1$, column $2$ and the cell at row $2$, column $1$, which makes $2$ cells.
Both of these $2$ cells have $2$ written in them, so the condition is satisfied for this cell.

By similar reasoning, it can be seen that this output satisfies the condition.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。