問題一覧 > 通常問題

No.1123 Afforestation

レベル : / 実行時間制限 : 1ケース 2.500秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 16
作問者 : e869120 / テスター : hirakich1000000007
お気に入りにしたユーザー ProblemId : 4633 / 自分の提出
問題文最終更新日: 2020-07-22 21:42:23
Afforestation
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. Show the original
yukicoder contest 258 (順位表) の他の問題:

Problem Statement

There is an $H \times W$ grid. The square in the $i$-th row from the top and the $j$-th column from the left is denoted by $(i, j)$; in particular, the top-left square is $(1, 1)$.
Among the $HW$ squares, $K$ squares have houses built on them, located at squares $(x_1, y_1)$, $(x_2, y_2)$, ..., $(x_K, y_K)$.
E869120 wants to choose, for each square without a house, whether to plant $1$ tree on it, so that the following conditions are satisfied.

  • In row $i$ $(1 \leq i \leq H)$, exactly $A_i$ trees are planted in total.
  • In column $j$ $(1 \leq j \leq W)$, exactly $B_j$ trees are planted in total.
Determine whether there exists a way of planting trees that satisfies the conditions.
If one exists, output one such way of planting.

Input

$H$ $W$
$A_1$ $A_2$ $A_3$ ... $A_H$
$B_1$ $B_2$ $B_3$ ... $B_W$
$K$
$x_1$ $y_1$
$x_2$ $y_2$
$x_3$ $y_3$
: :
$x_K$ $y_K$

The $1$st line contains integers $H$, $W$, separated by spaces.
The $2$nd line contains integers $A_1$, $A_2$, ..., $A_H$, separated by spaces.
The $3$rd line contains integers $B_1$, $B_2$, ..., $B_W$, separated by spaces.
The $4$th line contains an integer $K$.
The $5+i$-th $(1 \leq i \leq K)$ line contains integers $x_i, y_i$, separated by spaces.

Output (if no way of planting trees exists)

Output :( on $1$ line.

Output (if a way of planting trees exists)

Output $H+1$ lines as follows.

  • On the $1$st line, output Yay!.
  • For $1 \leq i \leq H$, on the $i+1$-th line, output a string of $W$ characters. The $j$-th ($1 \leq j \leq W$) character of the string must be as follows.
    • If square $(i, j)$ has a house: x
    • If square $(i, j)$ has no house and a tree is planted on that square: o
    • If square $(i, j)$ has no house and no tree is planted on that square: .

Constraints

  • $1 \leq H, W \leq 2 \ 000$
  • $0 \leq A_i \leq W$
  • $0 \leq B_i \leq H$
  • $1 \leq x_i \leq H$
  • $1 \leq y_i \leq W$
  • $0 \leq K \leq 16$
  • $(x_i, y_i) \neq (x_j, y_j)$ $(i \neq j)$
  • All inputs are integers.

Sample

Sample 1
Input
3 3
1 1 1
1 1 1
3
1 1
2 2
3 3
Output
Yay!
xo.
.xo
o.x

The following output is also accepted. Note that if there are multiple outputs satisfying the conditions, any of them will be accepted.

Yay!
x.o
ox.
.ox
Sample 2
Input
4 5
3 2 3 2
1 3 2 2 3
3
1 2
2 3
4 4
Output
:(

There is not even 1 way of planting trees that satisfies the conditions.

Sample 3
Input
8 8
7 6 5 5 4 4 3 2
7 7 6 5 5 2 2 2
3
8 6
8 7
8 8
Output
Yay!
ooooo.oo
oooooo..
ooooo...
ooooo...
ooo....o
oo...oo.
..ooo...
oo...xxx

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