아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Parking Lot

면접 대비

시간 제한5초메모리 제한1024 MB

요약
빈 칸과 주차된 차로 이루어진 r×c 격자에서 왼쪽 위 모서리에서 오른쪽 아래 모서리까지 가장 빠르게 걸어가는 시간을 구합니다.
난이도

보통10점 중 6점

유형
최단 경로, 그래프, 기하, 구현
정답자
아직 제출이 없습니다

문제

Walking across a huge parking lot is not only time consuming but also challenging because cars block your way and you may even get lost!

Imagine you are walking across a parking lot of r rows and c columns of parking spots. All parking spots have a size of a unit square. A parking spot either is empty or contains a parked car. You can walk across an empty parking spot in any direction, but can only walk along the boundaries of a parking spot if there’s a parked car in it. You start at the top-left corner of the parking lot and walk at a constant speed of one unit distance per second. If you pick the fastest route, in how many seconds can you walk to the bottom-right corner of the parking lot?

The image illustrates two possible routes for the parking lot in the first sample case. The blue route is the fastest route in this case. The red route shows that you can walk along the boundaries of parked cars.

입력

The first line of input has two integers r and c (1 ≤ r, c ≤ 50). The next r lines each have a string of c characters giving one row of parking spots from top to bottom. A dot ‘.’ indicates an empty parking spot and a hash ‘#’ indicates a parking spot with a parked car.

출력

Output the smallest amount of time in seconds you need to walk to the bottom-right corner of the parking lot. Your answer is considered correct if it has an absolute or relative error of at most 10−6 from the correct answer.

예제2

  1. 예제 1

    입력
    4 4
    ..#.
    .#.#
    ###.
    .#..
    
    예상 출력
    5.886349517
    
  2. 예제 2

    입력
    2 2
    ##
    ##
    
    예상 출력
    4.000000000