All submissions for this problem are available.
Treasure Hunting is a great computer game that has attracted generations of Bytelandian children.
In the game, there is a maze divided into NxN squares. Dave starts in the top-left corner, which is square (1,1), and needs to go to the bottom-right corner, which is square (n,n).
Some of the squares are blocked and some of the squares contain treasures.
Dave needs to capture all the treasures in the maze before going to square (n,n).
In each second, Dave can go to one of its four adjacent squares (if the destination is not blocked).
Find the earliest time that Dave can reach the destination(n,n) after collecting all the treasures in the maze.
The first line contains t, the number of test cases (about 15). Then t test cases follow. Each test case has the following form.
The first line contains N (1 <= N <= 13), the size of the maze
The N following lines describe the maze. The meaning of the symbols is as follows:
'.' : an empty square
'*' : a treasure
'#' : a blocked square
The number of treasures in the maze does not exceed 13. Squares (1,1) and (n,n) are always empty.
Each test case's input is separated by a blank line.
For each test case, print in a single line the earliest time that Dave can reach the destination after collecting all the treasures. If Dave cannot reach the destination, print -1.
Input: 4 3 ... .## *#. 3 ..* ... ... 3 ..* *.. ... 4 .... .#.* .#*. **#. Output: -1 4 6 16
|Time Limit:||0.444444 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, SQL, kotlin, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.