#abc358f. F - Easiest Maze
F - Easiest Maze
Score : points
问题陈述
Snuke计划在AtCoder Land建造一个新的迷宫景点。迷宫由一个行列的网格表示,右上角单元格的上边缘是入口,右下角单元格的下边缘是出口。他将通过在相邻单元格之间适当放置墙壁来创建迷宫。
他喜欢简单的迷宫,所以他希望从入口到出口的路径正好穿过个单元格,没有任何分支。确定是否可以创建这样的迷宫,如果可能,构建一个。
例如,在下面的图中,,,墙壁放置在实线上(墙壁总是围绕外周边缘放置,除了入口和出口)。在这种情况下,从入口到出口的路径正好穿过个单元格,没有任何分支。
下面是正式的陈述。
有一个行列的网格。让表示从顶部数第行,从左侧数第列的单元格。对于每一对相邻的单元格,你可以决定是否在它们之间放置一堵墙。确定是否可以放置墙壁以满足以下条件,如果可能,构建一个这样的放置。
考虑一个有个顶点的无向图。的每个顶点都由一对整数唯一标记。如果并且网格上相应的单元格和之间没有墙壁,则两个不同的顶点和通过一条边连接。
条件:存在一条有个顶点的简单路径,连接两个顶点和,并且包含顶点和的连通分量仅由这条路径组成。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
Snuke is planning to build a maze as a new attraction in AtCoder Land. The maze is represented as a grid with rows and columns, with the top edge of the top-right cell being the entrance and the bottom edge of the bottom-right cell being the exit. He will create the maze by appropriately placing walls between adjacent cells.
He loves simple mazes, so he wants the path from the entrance to the exit to pass through exactly cells without any branches. Determine if it is possible to create such a maze, and if possible, construct one.
For example, in the following figure, and , and walls are placed at the solid lines (walls are always placed around the outer perimeter except for the entrance and exit). In this case, the path from the entrance to the exit passes through exactly cells without any branches.
Below is a formal statement.
There is a grid with rows and columns. Let denote the cell at the -th row from the top and -th column from the left. For each pair of side-adjacent cells, you can decide whether to place a wall between them. Determine whether it is possible to place walls to satisfy the following condition, and if it is possible, construct one such placement.
Consider an undirected graph with vertices. Each vertex of is uniquely labeled by a pair of integers . Two distinct vertices and are connected by an edge if and only if and there is no wall between the corresponding cells and on the grid.
Condition: there exists a simple path with vertices that connects the two vertices and , and the connected component containing the vertices and consists only of this path.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
If there is no placement of walls that satisfies the condition, print No
. Otherwise, print one such placement in the following format. If multiple valid placements exist, any of them can be printed.
See also the sample outputs below to better understand the complicated output format.
Yes
+++++ +++S+
+o?o? ?o?o+
+?+?+ +?+?+
+o?o? ?o?o+
+?+?+ +?+?+
+o?o? ?o?o+
+?+?+ +?+?+
+o?o? ?o?o+
+++++ +++G+
Here, S
, G
, +
, and o
represent the entrance, exit, a wall, and a cell, respectively, and ?
between cells represents a position where a wall can be placed. Replace ?
between two horizontally adjacent cells with |
if a wall is placed, and .
otherwise. Replace ?
between two vertically adjacent cells with -
if a wall is placed, and .
otherwise.
Below is a formal instruction.
-
The output should consist of lines. Line should contain the string
Yes
, and lines to should contain strings of length as described below.-
Line should be a concatenation of
+
repeated times,S
, and+
, in this order. -
Line should be a concatenation of
+
,o
, ,o
, , , ,o
,+
, in this order. Here, is|
if a wall is placed between cells and , and.
otherwise. -
Line should be a concatenation of
+
, ,+
, ,+
, ,+
, ,+
, in this order. Here, is-
if a wall is placed between cells and , and.
otherwise. -
Line should be a concatenation of
+
repeated times,G
, and+
, in this order.
-
Sample Input 1
3 3 7
Sample Output 1
Yes
+++++S+
+o.o.o+
+.+-+-+
+o.o.o+
+-+-+.+
+o.o|o+
+++++G+
This is the same placement of walls as in the figure in the problem statement.
Sample Input 2
3 3 2
Sample Output 2
No
Sample Input 3
4 1 4
Sample Output 3
Yes
+S+
+o+
+.+
+o+
+.+
+o+
+.+
+o+
+G+