Blocks
Time limit1sMemory limit128 MB
Move adjacent block pairs into empty cells in the fewest moves to gather N A's and N B's into separate consecutive groups.
- Level
Hard8 of 10
- Topics
- Simulation, Greedy, Brute force
- Solved
- No attempts yet
Problem
A grid has blocks in the rightmost cells.
You may pick two consecutive occupied cells and move them to two consecutive empty cells. Block order must be preserved, and the destination must also be two consecutive cells.
Move the blocks the minimum number of times so that consecutive 'A' blocks and consecutive 'B' blocks are formed. There are 9 valid final arrangements.
Input
One line with ().
Output
Print moves in the form X to Y, meaning the blocks at cells and move to cells and (, ). Any optimal answer is accepted.