DWITE '11 R3 #4 - ABCA Maze
View as PDFDWITE, December 2011, Problem 4
It's the night before DWITE, and we're a question short. I just finished my exams a few hours ago, but AJ is gone, studying somewhere in the bowels of University's campus. Though instead of recycling an old question, here's a new one, albeit with a generic story.
You suddenly find yourself to be a letter A, and also in a maze. Your task is to locate letter B, then letter C, then return to your starting point. Why are you doing this? I don't know. But you need to also find the shortest distance that this can be accomplished in.
#denotes a wall.denotes open spaceA,B,Cdenotes various points of interest
You can move only up/down/left/right, not through walls, and not outside of the maze's bounds.
The input will contain 5 test cases. Each case will start with 2 space separated integers , the number of rows and columns that describe the size of a maze, followed by
lines, each
characters long – the actual maze.
The output will contain 5 lines of output, each the shortest distance for the A → B → C → A circuit.
Sample Input
1 6
#A.BC#
3 6
##A###
#C.###
##...B
Sample Output
6
12
Problem Resource: DWITE
Comments