시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 1024 MB | 41 | 6 | 6 | 35.294% |
President K loves solving mazes. He found cells from which he may create a maze. The cells are rectangular grid with $R$ horizontal rows and $C$ vertical columns. Each cell is colored either white or black. The cell in the $i$-th row ($1 ≤ i ≤ R$) from the top and the $j$-th column ($1 ≤ j ≤ C$) from the left is called Cell $(i, j)$.
President K will solve the maze under the condition that he can pass the white cells, but he cannot pass the black cells. More precisely, he will solve the maze in the following way.
President K already fixed the starting cell and the goal cell. However, he noticed that in some situations of the colors of the cells, there might not be a path from the starting cell to the goal cell consisting of white cells only. He has a stamp of size $N \times N$. He will perform the following Operations several times so that there will be a path from the starting cell to the goal cell consisting of white cells only.
Operation He chooses a square region of $N \times N$ cells, and paint the cells in the region white. More precisely, he chooses integers $a$, $b$ satisfying $1 ≤ a ≤ R - N + 1$ and $1 ≤ b ≤ C - N + 1$, and for every pair $(i, j)$ of integers satisfying $a ≤ i ≤ a + N - 1$ and $b ≤ j ≤ b + N - 1$, he paints Cell $(i, j)$ white.
Since his hands becomes dirty if he uses the stamp, he wants to minimize the number of operations. Given information of the colors of the cells, the size of the stamp, and the locations of the starting cell and the goal cell, write a program which calculates the minimum number of operations he has to perform so that there will be a path from the starting cell to the goal cell consisting of white cells only.
Read the following data from the standard input.
$R$ $C$ $N$
$S_r$ $S_c$
$G_r$ $G_c$
$A_1$
$A_2$
$\vdots$
$A_R$
$A_i$ ($1 ≤ i ≤ R$) is a string of length $C$ consisting of .
or #
. The $j$-th character ($1 ≤ j ≤ C$) of $A_i$ represents the color of Cell $(i, j)$. Its color is white if the character is .
, and its color is black if the character is #
.
Write one line to the standard output. The output should contain the minimum number of operations President K has to perform so that there will be a path from the starting cell to the goal cell consisting of white cells only.
.
or #
.번호 | 배점 | 제한 |
---|---|---|
1 | 8 | $N = 1$, $R \times C ≤ 1\,500\,000$. |
2 | 19 | $R \times C ≤ 1\,000$. |
3 | 16 | The answer is less than or equal to $10$, and $R \times C ≤ 1\,500\,000$. |
4 | 19 | $R \times C ≤ 60\,000$. |
5 | 5 | $R \times C ≤ 150\,000$. |
6 | 19 | $R \times C ≤ 1\,500\,000$. |
7 | 8 | $R \times C ≤ 3\,000\,000$. |
8 | 6 | No additional constraints. |
2 4 2 1 1 2 4 .### ###.
1
If he chooses $(a, b) = (1, 2)$ and perform an operation, Cells $(1, 2)$, $(1, 3)$, $(2, 2)$, $(2, 3)$ become white. Then there will be a path from the starting cell to the goal cell consisting of white cells only. For example, the path $(1, 1) → (1, 2) → (1, 3) → (2, 3) → (2, 4)$ satisfies the condition.
If he does not perform an operation, there is no path from the starting cell to the goal cell consisting of white cells only. Therefore, output $1$.
This sample input satisfies the constraints of Subtasks 2, 3, 4, 5, 6, 7, 8.
6 6 1 1 6 6 1 ..#.#. ##.### ####.# ...### ##.##. .#.###
4
This sample input satisfies the constraints of all the subtasks.
6 7 6 6 4 3 1 ..#.#.# ##.##.. .###### #..#.#. .###### ..#.##.
1
This sample input satisfies the constraints of Subtasks 2, 3, 4, 5, 6, 7, 8.
1 15 1 1 15 1 1 ...............
0
Even if he does not perform an operation, there might be a path from the starting cell to the goal cell consisting of white cells only.
This sample input satisfies the constraints of all the subtasks.