キーエンスプログラミングコンテスト2022(AtCoder Beginner Contest 274)
G
Security Camera 3
AtCoder
⌀ 2340
原题
← Ex→
翻译中…

Problem Statement

翻译中…

There is a grid with $H$ rows from top to bottom and $W$ columns from left to right. Let $(i, j)$ denote the square at the $i$-th row from the top and $j$-th column from the left. Square $(i, j)$ is occupied by an obstacle if $S_{i,j}=$ #, and is empty if $S_{i,j}=$ ..

翻译中…

Takahashi will install some surveillance cameras in the grid.

翻译中…

A surveillance camera can be placed at a square without an obstacle, in one of the four directions: up, down, left, or right. Multiple surveillance cameras may be placed at the same square.

翻译中…

Each surveillance camera monitors the square it is placed at, and the squares in the direction it is placed in, as far as there is no obstacle in between.

翻译中…

At least how many surveillance cameras are needed to monitor all squares without an obstacle?

翻译中…

Constraints

翻译中…
  • $1 \leq H,W \leq 300$
  • $S_{i,j}$ is . or #.
翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3 3
...
.#.
...
Output #1
4
For example, if we install two surveillance cameras at square $(1, 1)$ facing right and down, and another two at square $(3, 3)$ facing up and left, all squares without an obstacle will be monitored.
Input #2
3 5
...##
.#...
...#.
Output #2
5
For example, if we install two surveillance cameras at square $(1, 1)$ facing right and down, another at square $(3, 3)$ facing left, and another two at square $(2, 5)$ facing left and down, all squares without an obstacle will be monitored. Note that the camera at square $(2, 5)$ facing left cannot monitor square $(2, 1)$, since there is an obstacle in between at square $(2, 2)$.
Input #3
14 107
...........................................................................................................
...........................................................................................................
..#########..###....###########..###.......###...###########..####.......###...###########...###########...
..########..###....###########....###.....###...###########...#####......###..###########...###########....
..#######..###.....###.............###...###....###...........######.....###..###...........###............
..######..###......###..............###.###.....###...........###.###....###..###...........###............
..#####..###.......############......#####......############..###..###...###..###...........############...
..####....###......############.......###.......############..###...###..###..###...........############...
..###......###.....###................###.......###...........###....###.###..###...........###............
..##........###....###................###.......###...........###.....######..###...........###............
..#..........###...############.......###.......############..###......#####..############..############...
..............###...###########.......###........###########..###.......####...###########...###########...
...........................................................................................................
...........................................................................................................
Output #3
91
题目信息
题号
abc274_g
时间限制
2 s
内存限制
1024 MB

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