프로그램 명: boi_maze
제한시간: 1 초

Consider the following maze made of equilateral triangles:

Each vertex is described by two coordinates x and y as in the picture. Some of the edges have a white or a black circle on them. There are two major rules that control movement within the maze:

TASK

Write a program to find the length of the shortest path from the entrance point to the exit in the maze. The length of the path is defined as the number of edges (or circles) passed. You may assume that such path always exists.

입력

출력

Your program should output a single integer (the length of the shortest path from entrance point to the exit in the maze) in the first (and the only) line

입출력 예

입력

2 1 
0 0 2 1 
bb 
nwwnw 
bn 

출력

6  

A simple maze. One possible shortest path is this: 
(0, 0) -> (1, 0) -> (0, 1) -> (1, 1) -> (1, 0) -> (2, 0) -> (2, 1)
Here is the illustration of the maze and the shortest path: 



입력

5 4 
0 2 5 2 
nnbnn 
nnnwwbwnnnn 
nbbbn 
nnwbwwbwwnn 
bwwww 
nnbwbbwwbnn 
nwwwn 
nnnnbwbbnnn 
nnwnn

출력

22  

This is the description of the maze given in the picture on the first page. The shortest path is this: 

(0, 2) -> (1, 2) -> (1, 1) -> (2, 1) -> (2, 0) ->
(3, 0) -> (3, 1) -> (3, 2) -> (4, 1) -> (3, 1) ->
(3, 0) -> (2, 0) -> (2, 1) -> (1, 1) -> (1, 2) ->
(1, 3) -> (2, 3) -> (2, 4) -> (3, 4) -> (3, 3) ->
(4, 3) -> (4, 2) -> (5, 2) 
(Length: 22)
출처:boi 2005

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]