AtCoder Regular Contest 214
F
Unpredictable Moves
AtCoder
⌀ 3787
原题
← E→
翻译中…

Problem Statement

翻译中…

There is an $H \times W$ grid. Let $(i,j)$ denote the cell at the $i$-th row from the top and $j$-th column from the left.

翻译中…

Each cell is an empty cell or a wall cell, and this information is represented by $H \times W$ characters $S_{1,1},\dots ,S_{H,W}$. Cell $(i,j)$ is an empty cell if $S_{i,j}$ is ., and a wall cell if it is #.

翻译中…

Initially, Takahashi is at cell $(1,1)$. He can move to a cell adjacent to his current cell in one of the four directions (up, down, left, right) any number of times. However, he cannot move in the same direction twice in a row. Also, he cannot move to a wall cell or outside the grid.

翻译中…

Before starting to move, he can destroy zero or more wall cells to change them into empty cells. What is the minimum number of wall cells he needs to destroy to reach cell $(H,W)$? Under the constraints of this problem, it can be proved that there exists a way to destroy wall cells so that he can reach cell $(H,W)$.

翻译中…

You are given $T$ test cases; solve each of them.

翻译中…

Constraints

翻译中…
  • $1 \le T \le 1000$
  • $2 \le H, W \le 100$
  • $S_{i,j}$ is . or #.
  • $S_{1,1}$ and $S_{H,W}$ are ..
  • The sum of $HW$ over all test cases is at most $3 \times 10^4$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

H W
S_{1,1}S_{1,2}\ldotsS_{1,W}
S_{2,1}S_{2,2}\ldotsS_{2,W}
\vdots
S_{H,1}S_{H,2}\ldotsS_{H,W}

翻译中…

Output

翻译中…

Output $T$ lines.

翻译中…

The $i$-th line should contain the minimum possible number of wall cells to destroy for Takahashi to reach cell $(H,W)$ for the $i$-th test case.

翻译中…

样例

Input #1
3
3 5
..##.
.#...
##.#.
2 3
..#
#..
13 13
.############
##.##..###..#
#.#.#.#.#.###
#...#..##.###
#.#.#.#.#.###
#.#.#.#.##..#
#############
#...##.##.#.#
###.#..##.#.#
#...##.##...#
#.####.####.#
#...#...###.#
############.
Output #1
2
0
13
For the first test case, Takahashi can reach cell $(H,W)$ by destroying two wall cells as shown below. ![image](https://img.atcoder.jp/arc214/78ec0e8b7eb9370afc68684193b87232.png) The left side shows an example of wall cells to destroy, and the right side shows an example of a movement path. Note that it is not necessary to minimize the number of moves, and it is allowed to visit the same cell more than once. For the second test case, he can reach cell $(H,W)$ without destroying any wall cells.
题目信息
题号
arc214_f
时间限制
2 s
内存限制
1024 MB

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