|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||512 MB||15||8||8||53.333%|
You are given a board of R rows and C columns where each cell is either a dry land (‘#’) or an icy land (‘.’). You can move to either one of the four directions (north, south, east, or west) in the board.
You can walk or standstill on any dry land without any problem; however, an icy land is very slippery. If you stand at cell (r, c) and decide to move on a particular direction, then you will move on that direction continuously until you reach a dry land or the border of the board.
For example, consider the following board of 6 rows and 7 column.
#...... .#..... ..##... ..##... ....... .#.....
Supposed your initial position is at cell (3, 7) and your moves are west, west, west, south, east, north, west, and west, respectively. Then your positions are (3, 7) → (3, 4) → (3, 3) → (3, 1) → (6, 1) → (6, 2) → (2, 2) → (2, 1) → (2, 1), thus, visiting 8 different cells. Note that cell (2, 1) is visited twice. Cells in which you only passed through are also not considered as visited, e.g., in the example above, if you move south from (3, 1), then you will pass through (4, 1) and (5, 1), and arrive at (6, 1); thus, (4, 1) and (5, 1) are not considered as visited from that particular move, only (3, 1) and (6, 1) are.
You are allowed to change any icy land into a dry land, and your goal is to make sure that you can always visit all the cells in the board regardless of your initial starting position; in other words, you do not know your starting position yet, but given the board, you want to make sure that you can achieve your goal. What is the minimum number of cells you need to change to ensure that your goal can be achieved?
Input begins with a line containing two integers: R C (1 ≤ R, C ≤ 500) representing the number of rows and columns of the board, respectively. The next R lines, each contains C characters representing the given board. Each character is either ‘#’ which represents a dry land or ‘.’ which represents an icy land.
Output contains an integer in a line representing the minimum number of cells you need to change to ensure that you can visit all the cells in the board regardless of your initial starting position.
4 4 .... .### ##.. ###.
We only need to change cell (3, 3).
.... .### ###. ###.
Let ‘N’ be north, ‘S’ be south, ‘W’ be west, and ‘E’ be east.