QOJ.ac

QOJ

Time Limit: 8 s Memory Limit: 2048 MB Total points: 100

#10481. Remodeling the Dungeon 2

統計

Icpca 王国的女王平静地居住在城堡中。一天,她决定重新装修城堡的地牢。

地牢是一个由方形单元格组成的矩形网格。有些单元格是可进入的房间,而另一些是不可进入的管道空间。所有相邻单元格之间都由墙壁隔开。部分相邻房间之间的墙壁上装有门,以便往来。地牢中任意两个房间之间都通过这些门有连通路径。

女王希望重新装修地牢,使得任意两个房间之间只有唯一的一条路径。此外,任何两个仅有一扇门的房间之间,必须通过偶数扇门连接。由于成本限制,装修过程中唯一能做的事情就是封锁部分(可能为零)门。

你的任务是找到一种符合女王要求的地牢装修方案。

输入格式

输入包含单个测试用例,格式如下:

$h$ $w$ $c_{1,1}c_{1,2} \dots c_{1,2w+1}$ $c_{2,1}c_{2,2} \dots c_{2,2w+1}$ $\vdots$ $c_{2h+1,1}c_{2h+1,2} \dots c_{2h+1,2w+1}$

两个整数 $h$ 和 $w$ 表示地牢的大小为 $h \times w$。它们的取值范围均在 1 到 400 之间(含边界)。

每个字符 $c_{i,j}$ ($1 \le i \le 2h + 1$, $1 \le j \le 2w + 1$) 要么是 ‘.’,要么是 ‘#’。这些字符按以下方式表示地牢的配置:

  • 当 $i$ 和 $j$ 均为偶数时,$c_{i,j}$ 表示位于地牢从北向南第 $i/2$ 行、从西向东第 $j/2$ 列的单元格,记为单元格 $(i/2, j/2)$。‘.’ 表示该单元格是房间,‘#’ 表示它是管道空间。
  • 当 $i$ 为奇数且 $j$ 为偶数时,它表示一堵墙。当 $i = 1$ 或 $i = 2h + 1$ 时,它是地牢外墙的一部分。在这种情况下,$c_{i,j}$ 总是 ‘#’。否则,$c_{i,j}$ 表示单元格 $((i-1)/2, j/2)$ 和 $((i+1)/2, j/2)$ 之间的墙。‘.’ 表示墙上有门,‘#’ 表示没有门。门仅安装在两个房间之间的墙上。
  • 当 $i$ 为偶数且 $j$ 为奇数时,它也表示一堵墙。当 $j = 1$ 或 $j = 2w + 1$ 时,它是地牢外墙的一部分。在这种情况下,$c_{i,j}$ 总是 ‘#’。否则,$c_{i,j}$ 表示单元格 $(i/2, (j-1)/2)$ 和 $(i/2, (j+1)/2)$ 之间的墙。‘.’ 表示墙上有门,‘#’ 表示没有门。门仅安装在两个房间之间的墙上。
  • 当 $i$ 和 $j$ 均为奇数时,$c_{i,j}$ 总是 ‘#’,对应墙壁的交点。

保证地牢中至少有一个房间,且地牢中任意两个房间之间都有一条或多条连通路径。

输出格式

如果无法按照女王的要求重新装修地牢,输出 No。否则,第一行输出 Yes,随后输出重新装修后的地牢配置,格式与输入相同。如果存在多种可能的配置,输出其中任意一种即可。

样例

样例输入 1

3 3
#######
#.....#
#.#.###
#.#...#
#.#.#.#
#.....#
#######

样例输出 1

Yes
#######
#.....#
#.#####
#.#...#
#.###.#
#.....#
#######

样例输入 2

3 3
#######
#.....#
###.###
###...#
###.#.#
#.....#
#######

样例输出 2

Yes
#######
#.....#
###.###
###...#
#####.#
#.....#
#######

样例输入 3

3 3
#######
#.....#
#.###.#
#.###.#
#.###.#
#.....#
#######

样例输出 3

No

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.