A1228 | [COCI-2011_2012-contest3]#5 ROBOT
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Mirko created a new robot and decided to test it on a giant test track. We can imagine the test track as 2D coordinate system. The robot starts at a point (0, 0) and receives a set of instructions denoted by letters S, J, I, Z, each of them marking a direction in which robot should be moving.
More precisely, if a robot is located in (x, y), S (“north”) means it should move to (x, y+1), J (“south”)
means it should move to (x, y-1), I (“east”) means it should move to (x+1, y) and Z (“west”) means it should move to (x-1, y).
While robot is receiving instructions and moves through the test track, Mirko is verifying its position in the following manner. Test track contains N fixed control points. After each instruction is made, each of the control points measures manhattan-distance to the robot. Distances from all control points are then summed and sent to Mirko.
Assuming that robot moves by the instructions without error, calculate the sum of distances to all control points after each instruction.
Remark: manhattan-distance of the points (x1, y1) and (x2, y2) is equal to |x1 - x2| + |y1 - y2|.
More precisely, if a robot is located in (x, y), S (“north”) means it should move to (x, y+1), J (“south”)
means it should move to (x, y-1), I (“east”) means it should move to (x+1, y) and Z (“west”) means it should move to (x-1, y).
While robot is receiving instructions and moves through the test track, Mirko is verifying its position in the following manner. Test track contains N fixed control points. After each instruction is made, each of the control points measures manhattan-distance to the robot. Distances from all control points are then summed and sent to Mirko.
Assuming that robot moves by the instructions without error, calculate the sum of distances to all control points after each instruction.
Remark: manhattan-distance of the points (x1, y1) and (x2, y2) is equal to |x1 - x2| + |y1 - y2|.
输入格式
First line of input contains positive integers N (number of control points, 1 ≤ N ≤ 100 000) and M (number of instructions, 1 ≤ M ≤ 300 000), separated by a single space.
Each of the following N lines contains coordinates of one control point: two space-separated integers x, y, with absolute value less than 1 000 000 (million). It is possible that two control points have the same coordinates - distance towards each of them is added to the sum.
The following line contains a string of M characters from the set {S, J, I, Z}, the sequence of instructions sent to the robot.
Each of the following N lines contains coordinates of one control point: two space-separated integers x, y, with absolute value less than 1 000 000 (million). It is possible that two control points have the same coordinates - distance towards each of them is added to the sum.
The following line contains a string of M characters from the set {S, J, I, Z}, the sequence of instructions sent to the robot.
输出格式
Output M lines: i-th line of output should contain the described number after i-th instruction.
输入输出样例
输入 #1
1 3 0 -10 ISI
输出 #1
11 12 13
输入 #2
3 5 0 0 1 1 1 -1 SIJJZ
输出 #2
5 4 3 4 5
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted