QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#3887. 逻辑谜题

统计

在最近的一次旅行中,你在报刊亭浏览时买了一本充满各种逻辑谜题的杂志。然而,在解了一段时间后,你开始对这些谜题感到有些厌倦。尽管如此,为了完成杂志上的所有谜题,你开始思考如何用算法来解决其中的一些。

你目前正在尝试解决的谜题叫做“马赛克”(Mosaic),它与经典的扫雷游戏非常相似:

图 L.1:第一个样例的说明

你拥有一个二维的单元格网格,初始时全部为白色,你需要将其中一些单元格涂成黑色。你还会得到一个线索数字网格,它在谜题网格的每个方向上都向外延伸了一个单元格。单元格中的数字表示以该单元格为中心的 $3 \times 3$ 区域内需要涂成黑色的单元格数量(精确值)。你不能在原始网格之外涂色。

输入格式

输入包含: 一行,包含两个整数 $h, w$ ($1 \le h, w \le 100$),表示谜题的高度和宽度; $h + 2$ 行,每行包含 $w + 2$ 个整数 $c_1, \dots, c_{w+2}$ ($0 \le c_i \le 9$),表示线索数字。

输出格式

如果给定的线索数字不一致,输出 impossible。否则,输出 $h$ 行,每行包含 $w$ 个字符,表示谜题的解。使用 X 表示黑色单元格,. 表示白色单元格。如果有多个解,输出其中任意一个即可。

样例

输入 1

2 3
1 1 2 1 1
1 2 3 2 1
1 2 3 2 1
0 1 1 1 0

输出 1

X.X
.X.

输入 2

1 2
0 0 1 1
0 1 1 1
0 1 1 1

输出 2

impossible

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.