No.3765 321-avoiding Grid
タグ : / 解いたユーザー数 36
作問者 :
apricity
/ テスター :
👑 Problem Statement
You are given an integer $N$ that is at least $2$ and positive integers $A,B,C$ satisfying $A+B+C = N^2$.
Show one example of a way to write one of the digits $1,2,3$ in each cell of a grid with $N$ rows and $N$ columns such that all of the following conditions are satisfied.
- There are exactly $A$ cells with $1$ written on them.
- There are exactly $B$ cells with $2$ written on them.
- There are exactly $C$ cells with $3$ written on them.
- Consider moving to a cell adjacent vertically or horizontally. There does not exist a way to start from some cell and repeat the move $2$ times such that the digits written on the visited cells are $3,2,1$ in this order.
It can be proved that at least $1$ way of writing satisfying the conditions exists.
Input
$N\ A\ B\ C$
- All inputs are integers.
- $2 \leq N \leq 500$
- $1 \leq A,B,C$
- $A+B+C = N^2$
Output
Let $S_{i,j}$ be the digit written in the cell at the $i$-th row from the top and the $j$-th column from the left. Output $S$ in the following format.
$S_{1,1}S_{1,2}\dots S_{1,N}$
$S_{2,1}S_{2,2}\dots S_{2,N}$
$\vdots$
$S_{N,1}S_{N,2}\dots S_{N,N}$
If there are multiple $S$ satisfying the conditions, any of them will be considered correct.
Sample
Sample 1
Input
2 2 1 1
Output
12 31
Let $(i,j)$ denote the cell at the $i$-th row from the top and the $j$-th column from the left. Below are examples of ways to repeat the move $2$ times.
- When moving $(1,1) \rightarrow (1,2) \rightarrow (2,2)$, the digits written on the visited cells are $1,2,1$ in this order.
- When moving $(2,1) \rightarrow (1,1) \rightarrow (1,2)$, the digits written on the visited cells are $3,1,2$ in this order.
There is no way of moving such that the digits written on the visited cells are $3,2,1$ in this order, so this way of writing indeed satisfies the conditions.
Sample 2
Input
3 4 4 1
Output
121 221 213
Sample 3
Input
3 3 3 3
Output
121 313 232
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。