P24971 [AtCoder] [ARC040C] Painting the Floor with Z
普及+
题目描述

Problem Description

Takahashi, the squid, loves painting the floor. The floor is divided into an $N \times N$ grid, and some of the squares are already painted. Let the square at the $ i $-th row and $ j $-th column be denoted as square $ (i,j) $. Takahashi is using a special ink-shooting device to paint the floor. With this device, he can paint the floor as follows:

  • By inputting any integers $ r $ and $ c $ and pressing the device's button, all squares $ (i,j) $ that satisfy either " $ i = r $ and $j \leq c$" or " $ i = r+1 $ and $j \geq c$" can be painted.

Takahashi wants to paint all the squares using this device. Find the minimum number of times the device needs to be used.

Input Format

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

$ N $ $ S_1 $ $ S_2 $ : $ S_N $

  • The first line contains an integer $ N $ ( $1 \leq N \leq 100$ ), representing the number of squares on one side of the grid.
  • The next $ N $ lines contain the information about the grid. The $ i $-th line ( $1 \leq i \leq N$ ) contains a string $ S_i $ of length $ N $. The $ j $-th character ( $1 \leq j \leq N$ ) of this string represents the information of square $ (i,j) $ as follows:
  • . indicates that the square is not yet painted.
  • o indicates that the square is already painted.

Output Format

Output the minimum number of times the device needs to be used on a single line. End the output with a newline.

Sample Input and Output

Sample Input #1

7
...oooo
oo.....
ooooooo
ooooooo
.....oo
oooo...
ooooooo

Sample Output #1

2

Sample Input #2

4
.oo.
..oo
o..o
oo..

Sample Output #2

3

Sample Input #3

1
o

Sample Output #3

0

Notes/Hints

Sample Explanation 1

The ink-shooting device can paint the input pattern neatly.

Sample Explanation 3

It is possible that all squares are already painted from the beginning.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
7 ...oooo oo..... ooooooo ooooooo .....oo oooo... ooooooo
样例输出
2