Experiments with Gorlum
Time limit1sMemory limit64 MB
A creature repeats a move string K times and you report the smallest and largest squared distances from a laser over all visited points.
- Level
Medium6 of 10
- Topics
- Math, Simulation
- Solved
- No attempts yet
Problem
Yerzhan built a laser that measures the distance to a distant object. For the test he uses Gorlum, a creature he caught in the forest. Gorlum is not bright and performs exactly five commands.
L: one step to the left, from to .R: one step to the right, from to .F: one step forward, from to .B: one step backward, from to .I: Gorlum takes a shiny ring with glowing letters out of his pocket and stays where he is.
The laser sits at and Gorlum starts at . The command list is the string concatenated times (), and Gorlum performs the commands of one by one from the front.
The laser measures the distance to Gorlum once at the start and once after each command, so it takes measurements.
Report the smallest and the largest measured distance. A distance is usually irrational, so this problem asks for the squared distance instead. The squared distance is always an integer, the point with the smallest square is the closest point, and the point with the largest square is the farthest one.
Input
The first line contains a natural number ().
The second line contains the string . It consists only of L, R, F, B, I, and .
The third line contains the laser coordinates and , separated by a space.
The fourth line contains Gorlum's starting coordinates and , separated by a space.
Every coordinate is an integer with absolute value at most .
Output
Print the smallest and the largest squared distance on one line, separated by a space. Both values fit in a signed 64-bit integer.