Dungeon Master II
Generally, a brute force method has only two kinds of reply,
a. Accepted b. Time Limit Exceeded
You, probably, are familiar with Dungeon Master!!! You are trapped in a 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?
Input
The input file consists of a number of dungeons. Each dungeon description has 4 lines each containing 4 characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#'and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level.
Output
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form Escaped in x minute(s). where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line Trapped!