No.8063 Breadth-First Search
Problem Statement
Takahashi likes mazes. He is now trying to solve a maze on a two-dimensional board where he can move up, down, left, and right. The board is given in the following format.
・First, the size of the board and the coordinates of the start and goal of the maze are given.
・Next, a board is given with information on whether each cell is an empty cell (.) or a wall cell (#). The start and the goal are always empty cells, and the goal is always reachable from the start.
Output the minimum number of moves required to go from the start to the goal in this maze. Note that you cannot move diagonally.
Input
$R\ C$
$sy\ sx$
$gy\ gx$
$c_{(1,1)}\ c_{(1,2)}\ ...\ c_{(1,C)}$
$c_{(2,1)}\ c_{(2,2)}\ ...\ c_{(2,C)}$
$.$
$.$
$.$
$c_{(R,1)}\ c_{(R,2)}\ ...\ c_{(R,C)}$
$R,C$ are the number of rows and the number of columns, respectively.
$sy,sx$ are the coordinates of the start: $sy$ is the y-coordinate and $sx$ is the x-coordinate.
$gy,gx$ are the coordinates of the goal: $gy$ is the y-coordinate and $gx$ is the x-coordinate.
$c_{(i,j)}$ indicates whether $(i,j)$ is an empty cell or a wall cell: '.' means an empty cell and '#' means a wall cell.
$1\leq R,C \leq10^3$
$1\leq sy,gy \leq R$
$1\leq sx,gx \leq C$
Output
Print a newline at the end.
Sample
Sample 1
Input
4 4 2 2 3 3 #### #..# #..# ####
Output
2
Sample 2
Input
10 10 2 2 9 9 ########## #........# #.######.# #.######.# #.######.# #.######.# #.######.# #.######.# #........# ##########
Output
14
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
googol_S0