## DWITE '11 R3 #4 - ABCA Maze

View as PDF

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### 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 , the amount 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 ABCA circuit.

#### Sample Input

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

#### Sample Output

6
12