DWITE '11 R3 #4 - ABCA Maze

View as PDF

Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 64M

Problem type
DWITE, 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 space
  • A, B, C denotes 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 1 \le R, C \le 10, the number of rows and columns that describe the size of a maze, followed by R lines, each C characters long – the actual maze.

The output will contain 5 lines of output, each the shortest distance for the ABCA circuit.

Sample Input

1 6
#A.BC#
3 6
##A###
#C.###
##...B

Sample Output

6
12

Problem Resource: DWITE

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported

Comments

There are no comments at the moment.