#P9966. [THUPC 2024 初赛] 机器人
[THUPC 2024 初赛] 机器人
Problem Description
There are robots standing in a circle, numbered in counterclockwise order.
Each robot has two hands. Initially, Robot has its “left hand” pointing to Robot , and its “right hand” pointing to Robot .
Inside every robot, there are lines of “commands”. The “commands” have the following forms.
Commands
“Commands” are divided into “basic commands” and “advanced commands”. “Advanced commands” are more complex, but they are essentially not very different. Below we describe the format of these “commands” and what happens when they are “executed”. In the statement, the word “itself” always refers to the robot that owns this “command”.
Basic Commands
SLACKOFF: “slack off”, i.e. do nothing.MOVE h z: Move the -th hand counterclockwise by robots. When it means the “left hand”, and when it means the “right hand”, same below.SWAP h x y: Swap the -th line of “command” of the robot pointed to by the -th hand with its own -th line of “command”.MIRROR h x: “Mirror” (flip) the -th line of “command” of the robot pointed to by the -th hand, i.e. flip in that “command” ( becomes , becomes ). In particular, it has no effect on theSLACKOFFcommand; and for theTRIGGERcommand, it directly modifies inside the “command” that will be “executed” when “triggered”.REPLACE h x <COMMAND>: Replace the -th line of “command” of the robot pointed to by the -th hand with<COMMAND>, where<COMMAND>is a complete “command”.
Advanced Commands
-
ACTIVATE h: “activate” the robot pointed to by the -th hand, i.e. “execute” all of that robot’s “commands” in order. A later line is executed only after the previous line finishes executing. Note that when executing earlier “commands”, later “commands” may be changed; in that case, the changed “commands” should be executed. Only after all of that robot’s “commands” have been executed is this “command” considered finished. -
TRIGGER <COMMANDNAME>: <COMMAND>: Here<COMMANDNAME>is the name of a “command”, i.e. the first all-caps word in a “command”;<COMMAND>is a complete “basic command”. ATRIGGERcommand will not be “executed”, i.e. it is skipped during sequential “execution”. However, when some other robot finishes “executing” a “command”, and its “right hand” is pointing to itself, then its earliestTRIGGERcommand (if any) that satisfies the following conditions will be “triggered”, and the corresponding<COMMAND>is “executed” once:- If
<COMMANDNAME>is notTRIGGER, then the “command” that has just finished “executing” is a<COMMANDNAME>command; - If
<COMMANDNAME>isTRIGGER, then the “command” that has just finished “executing” is the “command” executed when aTRIGGERcommand is “triggered”.
After it finishes “executing”, it returns to the original “execution” order.
- If
You need to start from Robot and “activate” these robots in increasing order, round and round, and output information about the first executed commands.
Input Format
The first line contains three positive integers .
Then, the information of the robots is given in increasing order of their indices.
For each robot, the first line contains two non-negative integers , indicating the robot index pointed to by its “left hand” and by its “right hand”.
The next lines give the robot’s “commands” in order. The format of “commands” is as described in the statement.
Output Format
Output lines, describing the relevant information of the first commands that begin “executing”, in order. Output before each command starts “executing”, one per line, in the following format:
- When “slacking off”, output
Robot <id> slacks off.. Here<id>is an integer, the index of the robot “executing” the current “command”, same below. - When “moving”, output
Robot <id> moves its <side> hand towards Robot <id2>.. Here<side>isleftorright, indicating which hand is moved (leftfor “left hand”,rightfor “right hand”);<id2>is an integer, the index of the robot that this hand points to after moving. - When “swapping”, output
Robot <id> swaps a line of command with Robot <id2>.. Here<id2>is an integer, the index of the robot whose “command” is swapped. - When “mirroring” (flipping), output
Robot <id> modifies a line of command of Robot <id2>.. Here<id2>is an integer, the index of the robot whose “command” is mirrored. - When “replacing”, output
Robot <id> replaces a line of command of Robot <id2>.. Here<id2>is an integer, the index of the robot whose “command” is replaced. - When “executing” an
ACTIVATEcommand to “activate” (different from your round-by-round “activation”), outputRobot <id> activates Robot <id2>.. Here<id2>is an integer, the index of the robot being “activated”. TRIGGERcommands are not “executed”, so no output is needed for them; however, when they are “triggered”, you still need to output the information of the corresponding “basic command” being “executed” in the formats above.
2 2 5
0 0
MOVE 1 1
MOVE 0 1
0 1
TRIGGER MOVE: MOVE 0 1
SLACKOFF
Robot 0 moves its right hand towards Robot 1.
Robot 1 moves its left hand towards Robot 1.
Robot 0 moves its left hand towards Robot 1.
Robot 1 moves its left hand towards Robot 0.
Robot 1 slacks off.
2 2 4
0 1
ACTIVATE 1
SLACKOFF
0 1
SWAP 0 2 2
MIRROR 0 1
Robot 0 activates Robot 1.
Robot 1 swaps a line of command with Robot 0.
Robot 1 slacks off.
Robot 0 modifies a line of command of Robot 0.
3 2 6
1 2
ACTIVATE 0
ACTIVATE 0
2 1
SWAP 0 2 2
TRIGGER ACTIVATE: REPLACE 0 2 SLACKOFF
0 1
TRIGGER MIRROR: SLACKOFF
SLACKOFF
Robot 0 activates Robot 1.
Robot 1 swaps a line of command with Robot 2.
Robot 1 slacks off.
Robot 2 replaces a line of command of Robot 0.
Robot 0 slacks off.
Robot 1 swaps a line of command with Robot 2.
3 2 8
0 1
SLACKOFF
TRIGGER MOVE: SLACKOFF
1 2
TRIGGER TRIGGER: SLACKOFF
TRIGGER SLACKOFF: MOVE 0 1
2 0
TRIGGER SLACKOFF: MOVE 1 2
TRIGGER TRIGGER: MOVE 1 1
Robot 0 slacks off.
Robot 1 moves its left hand towards Robot 2.
Robot 2 moves its right hand towards Robot 1.
Robot 1 slacks off.
Robot 2 moves its right hand towards Robot 0.
Robot 0 slacks off.
Robot 1 slacks off.
Robot 2 moves its right hand towards Robot 2.
见附加文件的 5.in。
见附加文件的 5.ans。
Hint
Explanation of Sample #1
The “trigger” timing of TRIGGER commands is after the “execution” finishes. Note that it cannot “trigger” its own TRIGGER commands.
Explanation of Sample #2
Note that when executing earlier “commands”, later “commands” may be changed; in that case, the changed “commands” should be executed.
Explanation of Sample #3
When an ACTIVATE command “activates” another robot, only after all of that robot’s “commands” have been “executed” is this “command” considered finished.
Explanation of Sample #4
Only its earliest TRIGGER command that satisfies the conditions will be “triggered”.
Explanation of Sample #5
Selfless gifts? Powerful help?
Subtasks
It is guaranteed that the format of all commands is correct.
It is guaranteed that the input file length does not exceed .
It is guaranteed that at least “commands” can be “executed”.
Constraints: , , .
It is guaranteed that .
It is guaranteed that , , . All input numbers are integers.
Problem Usage Agreement
From the THUPC2024 (Tsinghua University Programming Contest and Collegiate Invitational Contest 2024) Preliminary Round.
The following “this repository” refers to the official THUPC2024 Preliminary Round repository (https://github.com/ckw20/thupc2024_pre_public).
-
Any organization or individual may use or repost the problems in this repository for free.
-
Any organization or individual, when using the problems in this repository, should do so free of charge and publicly. It is strictly forbidden to profit from these problems or to add special access restrictions to them.
-
If possible, when using the problems in this repository, please also provide ways to obtain resources such as testdata, reference solutions, and editorials; otherwise, please include the GitHub address of this repository.
Translated by ChatGPT 5