P27351 [AtCoder] Village Renovation
省选
题目描述

Problem Description

AtCoder Village is a rectangle consisting of $ N $ squares in the north-south direction and $ M $ squares in the east-west direction, totaling $N \times M$ squares.
Some of the squares are walls. If $ S_{i, j} $ is #, then the square at the $ i $-th position from the north and the $ j $-th position from the west is a wall. If it is ., then it is not a wall.
You will change exactly one wall square to a non-wall square. Find how many candidate squares there are to change so that the following condition is met:

  • All non-wall squares can reach each other by moving up, down, left, or right one square at a time, only through non-wall squares within AtCoder Village.

Input Format

The input is given from the standard input in the following format:

$ N $ $ M $ $ S_1 $ $ S_2 $ $ S_3 $ $\hspace{3pt} \vdots$ $ S_N $

Output Format

Output the number of candidate squares to change to a non-wall square that satisfy the condition.

Sample Input and Output

Sample Input #1

3 3
..#
#..
.##

Sample Output #1

2

Sample Input #2

3 3
##.
##.
...

Sample Output #2

3

Notes/Hints

Constraints

  • $1 \le N \le 10$
  • $1 \le M \le 10$
  • $ N, M $ are integers
  • $ S_i $ is a string of length $ M $ consisting of # and . $(1 \le i \le N)$
  • There is at least one wall square and at least one non-wall square

Sample Explanation 1

For example, if you change the square at the 2nd position from the north and the 1st position from the west to a non-wall square, all non-wall squares can reach each other without going through walls. The square at the 3rd position from the north and the 2nd position from the west also satisfies the condition. No other wall squares satisfy the condition, so the answer is $ 2 $.

Sample Explanation 2

All wall squares except the one in the northwestmost position satisfy the condition. Note that all non-wall squares, including the newly created ones, must be able to reach each other.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 ..# #.. .##
样例输出
2