AtCoder Beginner Contest 243
Ex
Builder Takahashi (Enhanced version)
AtCoder
⌀ 3884
原题
←G →
翻译中…

Problem Statement

翻译中…

There is a grid with $H \times W$ squares. Let $(i,j)$ denote the square at the $i$-th row from the top and $j$-th column from the left. $C_{i,j}$ 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 $(i,j)$, he can go to $(i+1,j)$, $(i,j+1)$, $(i-1,j)$, or $(i,j-1)$. 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 $n$ of walls needed to prevent Aoki from reaching the goal, and
  • the number of ways modulo $998244353$, $r$, to achieve that minimum number of walls.
翻译中…

Constraints

翻译中…
  • $2 \leq H \leq 100$
  • $2 \leq W \leq 100$
  • $C_{i,j}$ is S, G, ., or O.
  • Each of S and G appears exactly once in $C_{i,j}$.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

H W
C_{1,1}C_{1,2}\dotsC_{1,W}
C_{2,1}C_{2,2}\dotsC_{2,W}
\vdots
C_{H,1}C_{H,2}\dotsC_{H,W}

翻译中…

Output

翻译中…

If it is possible to build walls to prevent Aoki from reaching the goal, print the string Yes and the integers $n$ and $r$ defined in the Problem Statement, in the following format:

翻译中…

Yes
n r

翻译中…

Otherwise, print No.

翻译中…

样例

Input #1
4 3
S..
O..
..O
..G
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:
Input #2
3 2
.G
.O
.S
Output #2
No
Regardless of how Takahashi builds walls, Aoki can always reach the goal.
Input #3
2 2
S.
.G
Output #3
Yes
2 1
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
Output #4
Yes
10 12
题目信息
题号
abc243_h
时间限制
4 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。