You have an
board. Some positions have objects that, when pressed, start moving in
the direction painted on them, until they leave the board, or until they
reach another object and stop just before crashing. The painted
directions are ‘>’ for rightwards, ‘<’
for leftwards, ‘’ for upwards and ‘v’ for downwards. The
goal of the game is to empty the board minimizing the number of times
that we press the objects.
Input consists of several cases, each with and , followed by lines with characters each. Periods indicate empty cells. Assume , that there is at least one object on the board, and that the game is solvable.
Be aware that the ‘’ char that Latex uses in the pdf of this statement is not an ASCII char. Use the html version of the statement to copy and paste the sample.
For every game, print the minimum cost to solve it.
The expected solution is neither a BFS nor a backtracking.
Input
1 4 >>>> 3 3 >.v ... ^.< 2 3 ^.> .<v 4 4 >>>v <..v ^..v ^<<< 4 3 >>v ^^> >^> ^^<
Output
4 5 4 14 13