문제
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 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 at which the titans will rush in. It takes unit of time to traverse zone (which corresponds to 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 , 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.