#abc243h. Ex - Builder Takahashi (Enhanced version)
Ex - Builder Takahashi (Enhanced version)
Score : points
问题描述
存在一个 的网格。令 表示从上数第 行、从左数第 列的方格。
表示每个方格的状态,每个方格处于以下四种状态之一:
S
:起点。网格中恰有一个起点。G
:终点。网格中恰有一个终点。.
:可建造区域,可以在该处建造墙壁。O
:不可建造区域,无法在该处建造墙壁。
Aoki 打算从起点出发并到达终点。当他位于 时,他可以移动到 、、 或 。不允许离开网格或进入有墙壁的方格。
Takahashi 决定在 Aoki 出发前,在他选择的一个或多个可建造方格上建造墙壁,以确保 Aoki 无法到达终点。在此情况下,起点和终点不能被选为建造墙壁的位置。
Takahashi 是否有可能通过建造墙壁来阻止 Aoki 达到终点?如果可能,还需计算以下两个值:
- 阻止 Aoki 达到终点所需的最少数目 的墙壁,
- 达到最少墙壁数目方式的数量模 的结果 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a grid with squares. Let denote the square at the -th row from the top and -th column from the left.
represents the state of each square. Each square is in one of the following four states.
S
: The starting point. The grid has exactly one starting point.G
: The goal. The grid has exactly one goal..
: A constructible square, where a wall can be built.O
: An unconstructible square, where a wall cannot be built.
Aoki intends to start at the starting point and get to the goal. When he is at , he can go to , , , or . It is not allowed to exit the grid or enter a square with a wall.
Takahashi decides to build a wall on one or more constructible squares of his choice before Aoki starts so that there is no way for Aoki to reach the goal. Here, the starting point and the goal cannot be chosen.
Is it possible for Takahashi to build walls to prevent Aoki from reaching the goal? If it is possible, also compute the two values below:
- the minimum number of walls needed to prevent Aoki from reaching the goal, and
- the number of ways modulo , , to achieve that minimum number of walls.
Constraints
- is
S
,G
,.
, orO
. - Each of
S
andG
appears exactly once in .
Input
Input is given from Standard Input in the following format:
Output
If it is possible to build walls to prevent Aoki from reaching the goal, print the string Yes
and the integers and defined in the Problem Statement, in the following format:
Yes
Otherwise, print No
.
Sample Input 1
4 3
S..
O..
..O
..G
Sample Output 1
Yes
3 6
Let #
represent a square to build a wall on. The six ways to achieve the minimum number of walls are as follows:
S#. S.# S.. S.. S.. S..
O#. O#. O## O.# O.# O.#
#.O #.O #.O ##O .#O .#O
..G ..G ..G ..G #.G .#G
Sample Input 2
3 2
.G
.O
.S
Sample Output 2
No
Regardless of how Takahashi builds walls, Aoki can always reach the goal.
Sample Input 3
2 2
S.
.G
Sample Output 3
Yes
2 1
Sample Input 4
10 10
OOO...OOO.
.....OOO.O
OOO.OO.OOO
OOO..O..S.
....O.O.O.
.OO.O.OOOO
..OOOG.O.O
.O.O..OOOO
.O.O.OO...
...O..O..O
Sample Output 4
Yes
10 12
update @ 2024/3/10 10:28:16