#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 55 attributes: atk,def,mat,mdf,fixatk,def,mat,mdf,fix, its current health hphp, its current coordinates (x,y,z)(x,y,z), its current horizontal facing ff (range 0077), and its vertical facing hh (range 0044).

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 hh. 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 ff. Left means increase, right means decrease, with wrap-around (corresponding to counterclockwise/clockwise when viewed from above).

For example, when h=4h=4, operation U is invalid. When f=0f=0, operation R will change ff to 77.

  • Repair (F): increase hphp by fixfix.

  • 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 atkatk and the target’s defdef (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 matmat and the target’s mdfmdf (if the difference is negative, it deals no damage).

Note: drones overlapping with the firing drone will not take damage.

If after taking damage, hp0hp\leq 0, then the drone crashes.

For ff and hh, “straight ahead” is defined as follows:

First, determine the x,yx,y direction based on ff, as shown in the figure below.

Then, further determine the direction based on hh.

  • For h=0h=0 or h=4h=4, straight ahead is straight down or straight up (x,yx,y unchanged, zz changes).

  • For h=1h=1 or h=3h=3, based on the horizontal direction above, also move one cell down/up.

  • For h=2h=2, straight ahead is the horizontal direction (x,yx,y as above, zz unchanged).

(Some people reported that the direction is hard to understand. Here is the direct correspondence table of f,hf,h and the straight-ahead (x,y,z)(x,y,z).)

Now, Steve has told you the initial state of all drones and the operations they execute afterward.

You need to tell him, after tt moments of fighting, the position and health of each drone.

Input Format

The first line contains two integers n,tn,t, representing the number of drones and the number of moments.

The next nn lines each contain 1111 integers and a string of length tt, describing the drones in order of their IDs.

These 1111 integers are x,y,z,h,f,atk,def,mat,mdf,hp,fixx,y,z,h,f,atk,def,mat,mdf,hp,fix, where hphp is the initial health.

Each character in the string is an uppercase letter, representing the operation at each of the tt moments in order.

Output Format

Output nn lines, each with 44 integers x,y,z,hpx,y,z,hp.

If the drone has not crashed, output its coordinates and final health.

Otherwise, output its coordinates right before crashing, and output 00 for hphp.

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 11 shoots down Drone 22 first. Since Drone 22 has already crashed, Drone 11 will not be shot down.

Behind them there are two drones following respectively. Drone 22 uses a laser, so Drone 33 will also take damage. Drone 11 uses bullets, so Drone 44 will not take damage. This continues until Drone 22 crashes, after which Drone 11 fires one last bullet and deals 11 point of damage to Drone 44. At the same time, in their first three operations, both drones performed three repairs, so hphp increases by 33.

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:

1n,t1001\leq n,t\leq 100

All input numbers are within reasonable ranges, and their absolute values are all at most 100100.

Among them, atk,def,mat,mdf,fixatk,def,mat,mdf,fix are non-negative integers.

hphp is a positive integer.

x,y,zx,y,z are integers.

hh is one of 0,1,2,3,40,1,2,3,4.

ff is one of 0,1,2,3,4,5,6,70,1,2,3,4,5,6,7.

The string contains only 88 kinds of characters: NFLRUDAMNFLRUDAM.

In addition, for the first 3 subtasks, it is guaranteed that at any moment, the drones’ zz coordinates are 00.

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