Hot Spot
Time limit1sMemory limit128 MB
On a 4 by 4 board, robots jump over one or two adjacent robots into an empty square; find the fewest jumps that bring the red robot to the top-left corner without violating the blue-robot adjacency rule.
- Level
Medium7 of 10
- Topics
- BFS, Graph, Simulation, Implementation
- Solved
- No attempts yet
Problem
Hot Spot is a single-player game played on a 4 by 4 board. The goal is to move a red robot from its current square to the top-left corner. The board may also contain green and blue robots. At any time, each square holds at most one robot.
A robot may move in one of two ways:
- If two robots are adjacent horizontally or vertically (never diagonally), one may jump over the other into the square immediately beyond, provided that square is empty. For example, if robot is immediately to the left of robot , then may jump to the square immediately to the right of .
- If three robots are in a row horizontally or vertically (again never diagonally), one of them may jump over the other two into the square immediately beyond, provided that square is empty. For example, if is immediately to the right of and is immediately to the right of , then may jump to the square immediately to the right of .
Every jump only changes the position of the jumping robot; robots are never removed from or added to the board.
A blue robot may never be adjacent, horizontally or vertically, to another blue robot or to the red robot; no move may create such an adjacency.
Given the initial board, determine the minimum number of jumps needed to bring the red robot to the top-left corner.
Input
The input describes the initial board as four lines, each containing four characters. Each character is one of: R for the red robot, B for a blue robot, G for a green robot, or . (a period) for an empty square.
Output
Output a single line with one integer: the minimum number of jumps needed for the red robot to reach the top-left square of the board.