Universal Cup Judging System

Universal Cup

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

給定兩個整數 $N$ 和 $M$。

請依照輸出格式的要求,輸出一個 $N \times N$ 的網格,其中的儲存格需塗成白色或黑色,並滿足以下條件。若不存在這樣的網格,請輸出 -1。

  • 網格中白色儲存格的連通分量大小,恰好包含 $M$ 種不同的數值。
  • 網格中黑色儲存格的連通分量大小,恰好包含 $M$ 種不同的數值。

若有多種解,輸出其中任何一種即可。

輸入格式

第一行包含兩個整數 $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

4 2

輸出格式 1

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

輸入格式 2

2 3

輸出格式 2

-1

輸入格式 3

12 7

輸出格式 3

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

說明

若兩個白色儲存格 $c_1, c_2$ 可以透過重複移動到垂直或水平相鄰的儲存格,且路徑上僅經過白色儲存格而互相到達,則稱它們是連通的。

一組白色儲存格集合 $S$ 被稱為連通分量,若 $S$ 滿足以下條件:

  • $S$ 中的任意兩個儲存格皆是連通的。
  • 任何不屬於 $S$ 的白色儲存格,皆不與 $S$ 中的任何儲存格連通。

黑色儲存格的連通分量定義亦同。

對於每個連通分量,其大小定義為該分量所包含的儲存格數量。

範例輸出 1 的說明: 白色儲存格的連通分量大小為兩個不同的數值 1 和 2。黑色儲存格的連通分量大小也為兩個不同的數值 4 和 6。

範例輸出 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.