問題一覧 > 通常問題

No.3335 ReCT

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 20
作問者 : 👑 kencho / テスター : cn_449 👑 みうね
お気に入りにしたユーザー ProblemId : 12741 / 自分の提出
問題文最終更新日: 2025-11-08 01:58:39
ReCT
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 487 (順位表) の他の問題:

Problem Statement

A figure formed by joining squares of the same size edge to edge is called a polyomino. In the following, the side length of the squares that make up a polyomino is $1$.

Now, we define "type $C$ polyominoes" and "type $T$ polyominoes" as follows.

  • Type $C$: a polyomino formed by joining $3$ or more squares in a straight line and then, from each of its two ends, joining $1$ or more squares in a straight line in the same direction
  • Type $T$: a polyomino formed by joining, from $1$ square, $1$ or more squares in a straight line in each of exactly $3$ directions
These definitions are illustrated below. Note that the orientation of a polyomino is not part of the definition.



Concrete examples of type $C$ and type $T$ are shown below.



Consider tiling a rectangular grid of width $H$ and height $W$ with these polyominoes so that the following conditions are satisfied.

  • Polyominoes must not extend outside the grid, and different polyominoes must not overlap
  • Each square that makes up a polyomino completely covers exactly $1$ cell of the grid

For each of the following cases, if a tiling satisfying the conditions exists, show one example of such a tiling; otherwise, report that none exists.
  • Case $C$: only type $C$ polyominoes are used
  • Case $T$: only type $T$ polyominoes are used
  • Case $CT$: at least $1$ type $C$ polyomino and at least $1$ type $T$ polyomino are used

Constraints

  • All input values are integers
  • $2 \leq H, W \leq 200$

Input

The input is given from standard input in the following format.

$H\ W$

Output

Output the answer in the following format, where $output_C, output_T, output_{CT}$ denote the outputs for case $C$, case $T$, and case $CT$, respectively.

$output_C$
$output_T$
$output_{CT}$

For each case, if no tiling satisfying the conditions exists, output -1; if one exists, output one example in the following format.

$K$
$A_{1, 1}\ A_{1, 2}\ \cdots\ A_{1, W}$
$A_{2, 1}\ A_{2, 2}\ \cdots\ A_{2, W}$
$\vdots$
$A_{H, 1}\ A_{H, 2}\ \cdots\ A_{H, W}$

$K$ is the number of polyominoes used, and $A_{i, j}$ is an integer between $1$ and $K$, inclusive, representing the polyomino that covers the cell in the $i$-th row from the top and the $j$-th column from the left of the grid.
Denoting the cell in the $i$-th row from the top and the $j$-th column from the left by $(i,\ j)$, it must hold that $A_{i_1, j_1} \neq A_{i_2, j_2}$ when the polyominoes covering $(i_1,\ j_1)$ and $(i_2,\ j_2)$ are different, and $A_{i_1, j_1} = A_{i_2, j_2}$ when they are the same.

Print a newline at the end.

See also the samples below for the details of each case and the output format.

Sample

Sample 1
Input
4 5
Output
3
1 1 1 2 2
1 3 1 3 2
1 3 3 3 2
1 2 2 2 2
4
2 2 2 2 1
3 2 1 1 1
3 3 3 4 1
3 4 4 4 4
3
3 3 3 3 3
2 2 2 3 1
2 1 1 1 1
2 2 2 2 1

The figure below illustrates the sample output.
In this example, the tiling uses $3$ type $C$ polyominoes in case $C$,
$4$ type $T$ polyominoes in case $T$,
and a total of $3$ polyominoes, namely $1$ type $C$ polyomino and $2$ type $T$ polyominoes, in case $CT$.

Sample 2
Input
2 2
Output
-1
-1
-1

The given rectangle is too small to place even one polyomino of either type $C$ or type $T$.

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