NASSA's Robot
InterviewTime limit1sMemory limit128 MB
You get a walk of UDLR steps with ? wildcards that can stop after any prefix, and you report the smallest and largest reachable X and Y.
- Level
Medium4 of 10
- Topics
- Greedy, Simulation
- Solved
- No attempts yet
Problem
NASSA's robot landed on Mars. The landing site can be modeled as an infinite two-dimensional plane with perpendicular and axes.
The robot keeps reporting its location back to Earth. Because of a serious design flaw it reports the moves it makes instead of the coordinates of its exact location, and some of the signals went missing before they reached the receiver.
During one exploration mission the robot sent a sequence of signals that can be written as a string over the characters U, R, D, L and ?. U is a step up ( increases by ), R is a step right ( increases by ), D is a step down ( decreases by ), L is a step left ( decreases by ), and ? is a missed signal. Every character of the string is a single step in the corresponding direction. A missed signal is a single step in one of the four directions. Before the robot starts sending the signals it is at coordinate and coordinate .
After sending some of the signals while moving, the robot's software crashed and it could not move any further. The researchers at the base want to narrow down the area they have to search. In other words, they want the minimum possible coordinate, the minimum possible coordinate, the maximum possible coordinate and the maximum possible coordinate of the place where the robot stopped.
Each of the four values is computed on its own. A single final position does not have to attain all four at once.
Input
The input contains several test cases. The first line holds one integer , the number of test cases (). Each of the next lines holds one non-empty string of at most characters, and each character is U, R, D, L or ?. This string is the sequence of signals described above.
Output
For each test case print one line with four integers separated by single spaces: the minimum possible coordinate, the minimum possible coordinate, the maximum possible coordinate and the maximum possible coordinate of the place where the robot stopped.