E: Dacey the Dice
https://open.kattis.com/problems/daceydice
Last updated
https://open.kattis.com/problems/daceydice
Last updated
This is a standard / problem.
The main challenge is keeping track of the orientation of the dice as it rolls along.
The key observation (as hinted in the question) is that any two adjacent faces uniquely determine the rest of the dice. So, it is sufficient to keep track of, say, the top and right face alone.
This way, our search space (and hence visited
tables used in search) are of size n*n*6*6 (x-coordinate, y-coordinate, top-face, right-face).
If the start location is (x1,y1)
and ending location is (x2,y2)
, we would like to start our search at (x1,y1,1,2)
and claim we found a path any time we hit a location of the form (x2,y2,2,*)
. Note that we end when we reach the destination with 5
at the bottom: this corresponds to having 2
at the top; the right face does not matter.