Pikulice
InterviewTime limit1sMemory limit1024 MB
Find the minimum number of slide and jump moves that turn a row of red and blue marbles with one empty stand into all reds, then the empty stand, then all blues.
- Level
Medium5 of 10
- Topics
- BFS, Graph, Simulation
- Solved
- No attempts yet
Subproblem
Marin has stands in a row. Exactly one stand is empty, and each of the other stands holds one red or blue marble. Marin moves marbles in one of two ways:
- Slide a marble next to the empty stand into the empty stand. The stand the marble left becomes empty.
- Jump a marble over an adjacent marble , provided and are different colors and the empty stand is adjacent to . lands on that empty stand, and the stand left becomes empty.
Each move takes one second.
One evening, Stjepan visited and said that the marbles must first all be red, then the empty stand, then all blue. Marin rearranged his marbles into that order as fast as he could. How many seconds did it take?