Our hero, Link, finds himself in a forest most plain. Scattered around him, northways, eastways, westways and southways, are open plots of grass, impenetrable woods, and scattered, rare Heart Pieces. This time, we wonder if Link can get just one of these Heart Pieces, and if so, how many steps he needs to take to reach it.
This link (1) contains a zip file, with a single file in the Input Format specified for this collection of problems, of mazes.
Let be the sum of the score for each maze. We define the score to be the index of the maze (1-based) multiplied by the minimum number of steps Link must take to reach a single Heart Piece, if he can. If no Heart Piece can be reached, the score for that maze is zero.
Find .
Example:
Input:
3
6 1
H.L..H
2 2
L#
#H
5 5
L....
####.
..H#.
.###.
.....
Output:
50
Output Explained:
In the first maze, there is are two Heart Pieces, but the one on the left is closer, at steps away instead of , so the score for the maze is (the index) times .
In the second maze, there is a single Heart Piece, but it cannot be accessed, so the score for that maze is zero.
In the third maze, there is a single Heart Piece, and it is reachable in precisely steps, so the score for this maze is .
Details:
in all mazes.
(1) - This link currently points to my Dropbox account, since there is currently no way to upload non-image content to Brilliant. Admin, feel free to delete this footnote if this is changed.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
This problem is the implementation of Dijkstra's Algorithm , Here is the C++ solution: