Insane Drift
Time limit0.5sMemory limit1024 MB
Given a target (X, Y), decide whether a car that doubles its step length on each repeated R or U can reach it in at most 4000 moves, and output a move sequence if so.
- Level
Medium7 of 10
- Topics
- Math, Greedy, Bit manipulation
- Solved
- No attempts yet
Problem
An infinitely large two-dimensional coordinate plane has Chaewan in a car at the origin. Chaewan can move the car by choosing one of the two operations below.
R: moves the car in the direction of increasing coordinate. IfRhas been chosen times in a row, the car moves .U: moves the car in the direction of increasing coordinate. IfUhas been chosen times in a row, the car moves .
Chaewan wants to reach the position using at most 4000 operations. Determine whether Chaewan can reach that coordinate, and if so, output any one sequence of operations. The car must be exactly at after all operations are performed for it to count as reached.
Input
The first line contains and , separated by a space. (, )
Output
If Chaewan can reach , output a string of length at least 1 and at most 4000 consisting only of the characters R and U. Applying the characters in order must place the car exactly at . If several answers exist, any of them is accepted.
If Chaewan cannot reach the position, output impossible.