#P7745. Robot Manhattan Path Sum
Robot Manhattan Path Sum
Robot Manhattan Path Sum
A robot is placed on a 2D coordinate system at the origin . It receives a sequence of commands represented by the characters S
, J
, I
, and Z
. These instructions indicate movements in the following way:
S
: move from to ,J
: move from to ,I
: move from to , andZ
: move from to .
There are fixed control points on the track. Each control point measures the Manhattan distance to the robot. The Manhattan distance between two points and is given by:
After executing each command, compute and output the sum of Manhattan distances from the robot's current position to all control points.
Note: The input starts with two integers and , where is the number of control points and is the number of commands. Then follow lines each containing two integers representing the coordinates of a control point. The final line contains a string of characters (each being one of S, J, I, or Z) representing the sequence of commands.
inputFormat
The first line contains two integers and .
The next lines each contain two integers and , representing the coordinates of a control point.
The last line contains a string of length consisting only of the characters S
, J
, I
, and Z
indicating the robot's commands.
outputFormat
Output lines. The -th line should contain the sum of Manhattan distances from the robot’s current position (after executing the first commands) to all control points.
sample
2 3
1 0
0 1
SIJ
2
2
2
</p>