Stranded Robot
Time limit4sMemory limit256 MB
Find the fewest moves for a robot on a 3D grid of ship blocks and vacuum to reach the teleporter, where each move depends on sunlight and gravity direction.
- Level
Hard8 of 10
- Topics
- BFS, Implementation, Graph
- Solved
- No attempts yet
Problem
A robot is stranded in the wreckage of an interstellar spaceship. Somewhere in the wreckage is a teleporter that can take the robot to safety.
The spaceship is spinning out of control along all axes. A nearby sun shines light on the wreckage. The ship also has an artificial gravity generator. The artificial gravity always pulls the robot away from the sun, regardless of the ship's orientation.
The robot has solar panels and must rely on solar power to move through the wreckage. When parts of the wreckage block the sun, the robot cannot move. The robot always anchors itself after every move, so it never thrashes about or falls into the void of space.
The wreckage and the area around it form a three-dimensional grid of size . Each block is either part of the ship or vacuum. The ship blocks may be disconnected.
The robot starts anchored to a piece of the ship. It decides on its own when to move and when to wait for the sun to shine from a convenient direction.
Gravity can pull the robot in one of 6 directions, 2 along each of the 3 axes. A cell is lit by the sun if there is no wreckage in the direction opposite to gravity from that cell. Before each move, the robot can choose the direction in which gravity pulls it. When making a move, both the original and the destination positions must be lit by the sun at the same time.
The following moves are allowed. The light always shines from above in the images. The blue (darker) block is the robot, and the orange (lighter) blocks are possible destinations.
- Moving across the floor
If the robot rests on top of a block, it can move to an adjacent position at the same height. The robot cannot move diagonally. The destination must also be lit by the sun.

- Jumping off a cliff
The robot can step off a raised position and then drop down. The drop can be any length.
The robot cannot drop into the void of space, or to an unlit position.

- Dropping down
If the robot is lit by the sun and finds itself hanging, it can drop down. This can happen when the gravity direction changes.
The robot cannot drop into the void of space.

The goal is to reach the teleporter, if possible, using the fewest moves. For the teleporter to work, the robot must be firmly anchored to the ship. So the robot must be at the teleporter at the end of a valid move. Dropping through the teleporter does not count. The teleporter does not block the sun or the robot's movement.
Input
The first line contains three integers , , ().
The spaceship and the area around it are described in blocks. The -th block describes the layer at height . Each block consists of lines, and the -th line of the -th block has symbols. The -th symbol is .
*is a full block.-is an empty block.Rmarks the block with the robot. There is exactly one.Tmarks the block with the teleporter. There is exactly one.
The robot is guaranteed to be connected to a full block.
Output
Print the minimum number of moves needed to reach the teleporter, or -1 if it cannot be reached.