Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

2つの整数 $N$ と $M$ が与えられる。

出力セクションで指定された形式に従い、各セルが白または黒に塗り分けられた $N \times N$ のグリッドを出力せよ。ただし、以下の条件を満たす必要がある。そのようなグリッドが存在しない場合は -1 を出力せよ。

  • グリッド内に現れる白いセルの連結成分のサイズは、ちょうど $M$ 種類の異なる値からなる。
  • グリッド内に現れる黒いセルの連結成分のサイズは、ちょうど $M$ 種類の異なる値からなる。

複数の解が存在する場合は、そのうちのどれを出力してもよい。

入力

1行目に整数 $N, M$ がこの順で空白区切りで与えられる。 ($ 2 \le N \le 2000, 1 \le M \le 2000 $)

出力

条件を満たすグリッドが存在する場合、$N$ 行出力せよ。$i$ 行目 ($1 \le i \le N$) には、長さ $N$ の文字列 $s_i$ を以下のように出力せよ。

  • 構築したグリッドの $i$ 行 $j$ 列目 ($1 \le j \le N$) のセルが白である場合、$s_i$ の $j$ 文字目は . (ドット) でなければならない。
  • 構築したグリッドの $i$ 行 $j$ 列目 ($1 \le j \le N$) のセルが黒である場合、$s_i$ の $j$ 文字目は # でなければならない。

条件を満たすグリッドが存在しない場合は、1行目に -1 を出力せよ。

入出力例

入力 1

4 2

出力 1

###.
..##
##.#
.##.

入力 2

2 3

出力 2

-1

入力 3

12 7

出力 3

.#..#.#.##.#
.#.#..#.##.#
.##...#.##.#
.#.#..#.##.#
.#..#.##..##
......######
######......
#...##..###.
#.##.#.#....
#...##.#....
#.####.#....
#.####..###.

注記

2つの白いセル $c_1, c_2$ は、白いセルのみを通って上下左右に隣接するセルへ繰り返し移動することで $c_1$ から $c_2$ へ移動できるとき、連結しているという。

白いセルの集合 $S$ は、以下の条件を満たすとき連結成分と呼ばれる。

  • $S$ 内の任意の2つのセルは連結している。
  • $S$ に含まれないいかなる白いセルも、$S$ に含まれるどのセルとも連結していない。

黒いセルの連結成分も同様に定義される。

各連結成分について、そのサイズはそれが含むセルの数として定義される。

サンプル出力 1 の説明

白いセルの連結成分のサイズは、1 と 2 の2種類の異なる値である。黒いセルの連結成分のサイズも、4 と 6 の2種類の異なる値である。

サンプル出力 1 の図

サンプル出力 3 の図

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1535EditorialOpen题解jiangly2026-04-15 16:06:30View
#1507EditorialOpenNew Editorial for Problem #17726incent2026-04-13 08:24:54View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.