AtCoder Regular Contest 112
D
Skate
AtCoder
⌀ 2028
原题
← CE →
翻译中…

Problem Statement

翻译中…

Takahashi is on a skating rink consisting of $H$ rows and $W$ columns of squares. Let $(r, c)$ denote the square at the $r$-th row from the north and $c$-th column from the west. Each square is ice or ground; $(r, c)$ is ground if $S_{r, c}$ is # and ice if $S_{r, c}$ is .. There are walls around the rink.

翻译中…

When Takahashi is standing still on the rink, he can start moving to the east, west, south, or north. After he starts moving, he will keep moving in the same direction, until he bumps into a wall or he is on a ground square (other than the square where he started moving).

翻译中…

We say the rink is efficient for $(r, c)$ when the following condition is satisfied:

翻译中…
  • There is a sequence of moves that starts at $(r, c)$, standing still, and passes every square. (It is not required to stop on each square.)
翻译中…

Takahashi wants to change some number of ice squares to ground squares so that the rink is efficient for every square. How many squares does he need to change, at least?

翻译中…

Constraints

翻译中…
  • $2\le H,W \le 1000$
  • $S_{r,c}$ is # or ..
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

H W
S_{1,1}\dots S_{1,W}
\vdots
S_{H,1}\dots S_{H,W}

翻译中…

Output

翻译中…

Print the minimum number of changes needed to make the rink efficient for every square.

翻译中…

样例

Input #1
3 9
.........
.........
.........
Output #1
1
Initially, it is impossible to start at $(1, 1)$ and pass $(2, 2)$. One way to meet the objective is to change the rink as follows:
Input #2
10 10
..........
#...#.....
..........
..........
..........
....#.....
.#......#.
..........
..........
..........
Output #2
6
题目信息
题号
arc112_d
时间限制
2 s
内存限制
1024 MB

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