#P7745. [COCI 2011/2012 #3] ROBOT
[COCI 2011/2012 #3] ROBOT
Description
We can think of the test track as a 2D coordinate system. The robot starts from and receives a sequence of commands represented by S, J, I, Z. Each command tells the robot which direction to move. Specifically, if the robot is currently at :
- Command
Smeans it should move to . - Command
Jmeans it should move to . - Command
Imeans it should move to . - Command
Zmeans it should move to .
While the robot receives commands and moves on the test track, Mirko checks its position in the following way:
There are fixed checkpoints on the test track. Each checkpoint measures the Manhattan distance to the robot, and sends the sum of all distances to Mirko. Assuming the robot moves exactly according to the commands, compute, after each command is executed, the sum of the Manhattan distances from all checkpoints to the robot.
Input Format
The input has lines.
The first line contains two integers , representing the number of checkpoints and the number of commands.
Lines to each contain two integers , representing the -coordinate and -coordinate of each checkpoint.
Line contains a string of length , representing the commands the robot will receive.
Output Format
Output lines. Each line contains one integer, the sum of the Manhattan distances from all checkpoints to the robot after executing each command.
1 3
0 -10
ISI
11
12
13
3 5
0 0
1 1
1 -1
SIJJZ
5
4
3
4
5
Hint
[Prerequisite Knowledge]
- Manhattan distance: given two points and , their Manhattan distance is .
[Constraints]
For all testdata, , , . The commands contain only one of S, I, J, Z.
[Source]
This problem is from COCI 2011-2012 CONTEST 3 T4 ROBOT. Using the original testdata configuration, the full score is points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5
京公网安备 11011102002149号