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