#P5506. 封锁
封锁
Description
To break through the blockade and land successfully, Steve used an electromagnetic jammer, causing the drones to start killing each other.
However, the situation quickly became chaotic, and it was impossible to understand what was happening.
Fortunately, Steve’s troops recorded the situation before the brawl started, and managed to obtain the order of operations executed by the drones.
Each drone has attributes: , its current health , its current coordinates , its current horizontal facing (range –), and its vertical facing (range –).
At each moment, all surviving drones will first move one cell straight forward.
Then, the surviving drones will in increasing order of their IDs execute exactly one of the following operations:
-
No operation (N).
-
Turn up/down (U/D): change the value of . Up means increase, down means decrease. If it goes out of range, the operation is invalid and should be ignored.
-
Turn left/right (L/R): change the value of . Left means increase, right means decrease, with wrap-around (corresponding to counterclockwise/clockwise when viewed from above).
For example, when , operation U is invalid. When , operation R will change to .
-
Repair (F): increase by .
-
Bullet (A): deal damage to the nearest drone located straight ahead of this drone. The damage value is the difference between the attacker’s current and the target’s (if the difference is negative, it deals no damage). If multiple drones are at the same position, only the one with the smallest ID takes damage.
-
Laser (M): deal damage to all drones straight ahead of this drone. The damage value is the difference between the attacker’s current and the target’s (if the difference is negative, it deals no damage).
Note: drones overlapping with the firing drone will not take damage.
If after taking damage, , then the drone crashes.
For and , “straight ahead” is defined as follows:
First, determine the direction based on , as shown in the figure below.

Then, further determine the direction based on .
-
For or , straight ahead is straight down or straight up ( unchanged, changes).
-
For or , based on the horizontal direction above, also move one cell down/up.
-
For , straight ahead is the horizontal direction ( as above, unchanged).
(Some people reported that the direction is hard to understand. Here is the direct correspondence table of and the straight-ahead .)

Now, Steve has told you the initial state of all drones and the operations they execute afterward.
You need to tell him, after moments of fighting, the position and health of each drone.
Input Format
The first line contains two integers , representing the number of drones and the number of moments.
The next lines each contain integers and a string of length , describing the drones in order of their IDs.
These integers are , where is the initial health.
Each character in the string is an uppercase letter, representing the operation at each of the moments in order.
Output Format
Output lines, each with integers .
If the drone has not crashed, output its coordinates and final health.
Otherwise, output its coordinates right before crashing, and output for .
4 7
-1 -1 0 2 1 1 0 0 0 5 0 RAAAAAA
51 0 1 1 4 0 0 1 0 5 0 UMMMMMM
-2 0 0 2 0 0 0 0 0 5 1 FFFNNNN
53 0 0 2 4 0 0 0 0 5 1 FFFNNNN
6 0 0 1
45 0 0 0
5 0 0 4
46 0 0 7
7 1
0 0 0 0 0 2 0 0 0 1 0 A
1 0 0 0 0 4 0 0 0 3 0 A
1 0 0 0 0 1 1 1 1 4 0 N
1 0 -1 0 0 0 0 0 0 2 0 N
0 1 0 0 0 0 0 3 0 3 0 M
0 1 -1 0 0 0 0 0 1 3 0 N
0 1 -1 0 0 0 0 0 2 3 0 N
0 0 -1 1
1 0 -1 3
1 0 -1 4
1 0 -2 2
0 1 -1 3
0 1 -2 1
0 1 -2 2
Hint
After two drones move and change their facing directions, they end up facing each other. Then they both fire crazily at each other. In the end, Drone shoots down Drone first. Since Drone has already crashed, Drone will not be shot down.
Behind them there are two drones following respectively. Drone uses a laser, so Drone will also take damage. Drone uses bullets, so Drone will not take damage. This continues until Drone crashes, after which Drone fires one last bullet and deals point of damage to Drone . At the same time, in their first three operations, both drones performed three repairs, so increases by .
During judging, each Subtask includes 3 test points. You can get the score of that Subtask only if you pass all of them.
Sample 2 explanation: https://www.luogu.com.cn/discuss/582252
Constraints:
All input numbers are within reasonable ranges, and their absolute values are all at most .
Among them, are non-negative integers.
is a positive integer.
are integers.
is one of .
is one of .
The string contains only kinds of characters: .
In addition, for the first 3 subtasks, it is guaranteed that at any moment, the drones’ coordinates are .
| Subtask | Score | Operations Appearing |
|---|---|---|
| 1 | 12 | N |
| 2 | 14 | NF |
| 3 | 15 | NFLR |
| 4 | 17 | NFLRUD |
| 5 | 19 | NFLRUDM |
| 6 | 23 | NFLRUDMA |
Translated by ChatGPT 5
京公网安备 11011102002149号