No.1398 Magic Circle of Harmony (Construction)
タグ : / 解いたユーザー数 79
作問者 :
CuriousFairy315
/ テスター :
37zigen
Problem Statement
315-san is studying magic circles.
Magic circles come in various shapes, such as pentagrams, hexagrams, and circular formations, and they take effect when catalysts of appropriate strength are placed on them.
The magic circle to be drawn this time is a rectangle divided into $H$ parts vertically and $W$ parts horizontally, and it takes effect by placing catalysts on its cells.
However, if a magic circle does not maintain harmony, the propagation of magical power becomes uneven, and the spell eventually collapses.
The magic circle to be drawn this time is said to maintain harmony if, for every cell, the sum $S$ of the strengths of the catalysts in the $3 \times 3$ cell area centered on that cell is the same.
That is, letting $M_{y, x}$ be the strength of the catalyst in cell $(x, y)$, it is required that $\sum_{i=y-1}^{y+1} \sum_{j=x-1}^{x+1} M_{i, j} = S$ for all integers $x, y$ satisfying $1 \leq x \leq W, 1 \leq y \leq H$.
In this case, the strength of the magic circle is $S$.
315-san has many catalysts with strengths between $1$ and $9$, inclusive, and wants to create a harmonious magic circle of strength $X$ by placing these catalysts appropriately.
At most 1 catalyst can be placed in each cell (a cell may also be left empty), so $0 \leq M_{y, x} \leq 9$ for all integers $x, y$ satisfying $1 \leq x \leq W, 1 \leq y \leq H$, and $M_{y, x} = 0$ for all other $x, y$.
There are as many as $10^{WH}$ ways to place catalysts on the magic circle in total, but what placements among them make the magic circle harmonious?
Given $W, H, X$, construct one harmonious magic circle of strength $X$.
Input
$W\ H\ X$
- $1 \leq W, H \leq 600$
- $0 \leq X \leq 81$
- All inputs are integers.
Output
If a harmonious magic circle with height $H$, width $W$, and strength $X$ can be created, output that magic circle; otherwise, output -1.
The magic circle is output as follows, where $M_{y,x}$ is the strength of the catalyst in cell $(x, y)$.
$M_{1, 1}M_{1, 2} \cdots M_{1, W}$
$\vdots$
$M_{H, 1}M_{H,2} \cdots M_{H, W}$
Print a newline at the end.
Sample
Sample 1
Input
2 2 6
Output
12 30
Any magic circle satisfying the conditions is accepted; it does not have to be the same as the one above.
For example,
60 00is also a correct answer.
Sample 2
Input
5 2 4
Output
11011 11011
Sample 3
Input
3 3 81
Output
-1
The catalysts 315-san has are not that strong, so such a powerful magic circle cannot be drawn.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。