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。

Figure for Sample Output 1

Figure for Sample Output 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.