問題一覧 > 通常問題

No.3765 321-avoiding Grid

レベル : / AI推定難易度 : 1750 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 1024 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 36
作問者 : apricity / テスター : 👑 AngrySadEight
お気に入りにしたユーザー ProblemId : 13639 / 自分の提出
問題文最終更新日: 2026-10-15 05:51:25
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 518 (順位表) の他の問題:

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