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

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

Escape Wall Maria

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

요약
방향에 따라 진입이 제한된 타일이 있는 격자에서 S에서 경계까지 t 시간 안에 도달하는 최소 이동 칸 수를 구한다.
난이도

보통10점 중 5점

유형
BFS, 그래프, 구현
정답자
아직 제출이 없습니다

문제

Wall Maria has been broken! Eren must evacuate as soon as possible from his house. He must find the fastest route to escape within Wall Maria before the titans rush in. Wall Maria is represented as a N×MN \times M grid in which Eren can move horizontally or vertically.

There are burning houses and buildings which prevent Eren from passing through them. The burning houses and buildings are represented as '1'. Unburned or safe areas are represented as '0'. There are some areas which can be entered but only from a specific direction. These areas can be represented by either 'U', 'D', 'L', or 'R'. For example, if there is an 'R' that means that area can only be entered from the right neighboring tile within Wall Maria's grid. Similarly, 'U' tiles can only be entered from above, 'D' tiles can only be entered from below, and 'L' tiles can only be entered from the left.

Eren knows the time tt at which the titans will rush in. It takes 11 unit of time to traverse 11 zone (which corresponds to 11 tile in the grid). Once he reaches any border of Wall Maria he is safe. 

Eren's starting position is represented by the letter 'S'. If Eren escapes at or before time tt, he is safe. Given his position within Wall Maria determine if it is possible to escape. If it is possible determine the number of zones that must be traversed to lead to the quickest escape.

입력

The input consists of a single test case. The first line contains three integers tt (1≤t≤2001 \le t \le 200) , NN (1≤N≤1001 \le N \le 100) and MM (1≤M≤1001 \le M \le 100). The rest of N lines will be Wall Maria's grid containing characters '1', '0', 'S', 'U', 'D', 'L', or 'R'. There is exactly one 'S' in the input.

출력

If it is possible to escape Wall Maria, output the minimum number of zones that must be traversed to escape. If it is not possible to escape, print "NOT POSSIBLE"!

예제3

  1. 예제 1

    입력
    2 4 4
    1111
    1S01
    1011
    0U11
    
    예상 출력
    2
    
  2. 예제 2

    입력
    2 4 4
    1111
    1S01
    1011
    0L11
    
    예상 출력
    NOT POSSIBLE
    
  3. 예제 3

    입력
    1 4 4
    1S01
    1001
    1011
    0U11
    
    예상 출력
    0