QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#6398. 谜题:Tapa

Estadísticas

Grammy 是一位解谜大师。今天,她正在玩一种名为“Tapa”的变体谜题。在这个变体中,在一个 $(2n - 1) \times (2m - 1)$ 的矩形网格上有 $n \times m$ 个线索。所有的线索都位于行索引和列索引均为奇数的单元格 $(i, j)$ 上。每个线索是一个数字,其值等于或比该线索周围的单元格数量少 1。具体来说,网格角落的线索可以是 2 或 3,网格边缘的线索可以是 4 或 5,网格中心的线索可以是 7 或 8。目标是涂黑一些单元格,使得:

  • 所有线索单元格均未被涂黑。
  • 每个线索单元格表示其周围连续被涂黑单元格的数量。

左上角的图片展示了一个只有线索的 $5 \times 5$ 网格,右上角的图片展示了一种可能的解法,底部的图片展示了一个错误的解法,因为围绕 4 的被涂黑单元格不是连续的。

Grammy 当然知道如何解这个谜题,但她决定给你出一道测验题。请解决这个谜题。

输入格式

第一行包含两个整数 $n, m$ ($2 \le n, m \le 50$),表示网格的大小。

接下来的 $2n - 1$ 行,每行包含 $2m - 1$ 个字符,表示带有给定线索的网格。点号(.)表示没有线索的单元格,而数字表示该单元格上的线索。保证所有行索引和列索引均为奇数的单元格上都有线索,且所有其他单元格均不包含任何线索。

输出格式

如果解不存在,输出一行 “NO”。

否则,第一行输出 “YES”,然后输出 $2n - 1$ 行,每行包含 $2m - 1$ 个字符,表示谜题的解。格式与输入网格类似,但你应该用 ‘#’ 标记被涂黑的单元格。换句话说,输出中的点号(.)表示没有线索且未被涂黑的单元格,井号(#)表示被涂黑的单元格,数字表示该单元格上的线索。

如果存在多个解,输出任意一个即可。

样例

样例输入 1

3 3
2.4.3
.....
5.8.5
.....
3.5.3

样例输出 1

YES
2.4#3
#####
5#8#5
#####
3#5#3

样例输入 2

3 3
3.4.3
.....
5.7.5
.....
3.5.3

样例输出 2

NO

样例输入 3

2 2
2.2
...
2.2

样例输出 3

YES
2.2
###
2.2

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.