eolymp
bolt
Try our new interface for solving problems
Problems

Dungeon Master II

Dungeon Master II

\textit{Generally, a brute force method has only two kinds of reply,} \textit{a. Accepted b. Time Limit Exceeded} You, probably, are familiar with Dungeon Master!!! You are trapped in a \textbf{4x4} 2D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to step one unit to north, south, east or west. You cannot move diagonally and the maze is surrounded by solid immovable rock on all sides. Also you have a power to move a rock in your neighborhood to another free unit in your neighborhood in one minute. Note that your neighbor units are north, south, east and west units. Is an escape possible? If yes, how long will it take? \InputFile The input file consists of a number of dungeons. Each dungeon description has \textbf{4} lines each containing \textbf{4} characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '\textbf{#}'and empty cells are represented by a '\textbf{.}'. Your starting position is indicated by '\textbf{S}' and the exit by the letter '\textbf{E}'. There's a single blank line after each level. \OutputFile Each maze generates one line of output. If it is possible to reach the exit, print a line of the form \textbf{Escaped in x minute(s).} where \textbf{x} is replaced by the shortest time it takes to escape. If it is not possible to escape, print the line \textbf{Trapped!}
Time limit 1 second
Memory limit 64 MiB
Input example #1
##.S
####
####
###E

..#S
.###
.##.
...E
Output example #1
Escaped in 5 minute(s).
Trapped!