#P9966. Robot Circle Instruction Execution

    ID: 23110 Type: Default 1000ms 256MiB

Robot Circle Instruction Execution

Robot Circle Instruction Execution

There are \(n\) robots arranged in a circle with indices \(0\) to \(n-1\) in counterclockwise order. Each robot has two hands. For robot \(i\), its initial left hand points to robot \(l_i\) and its right hand points to robot \(r_i\). Each robot stores \(m\) lines of instructions. The instructions come in two types: basic instructions and advanced instructions. Although advanced instructions (such as ACTIVATE and TRIGGER) have more complex behaviors, their effects are similar in nature to the basic instructions.

Instruction Set

Basic instructions:

  • SLACKOFF: Do nothing.
  • MOVE h z: Move the robot’s \(h\)th hand (where \(h=0\) is the left hand and \(h=1\) is the right hand) counterclockwise by \(z\) positions. Formally, if the current pointer value is \(x\), it becomes \((x+z) \bmod n\).
  • SWAP h x y: Swap the instruction at line \(x\) of the robot pointed to by the \(h\)th hand with the instruction at line \(y\) of the current robot.
  • MIRROR h x: Replace the instruction at line \(x\) of the robot pointed to by the \(h\)th hand with its mirrored version. In mirroring, any hand parameter \(h\) in that instruction is flipped (0 becomes 1 and 1 becomes 0). (Note: This has no effect for SLACKOFF and for TRIGGER the change applies to the command that will be executed.)
  • REPLACE h x <COMMAND>: Replace the instruction at line \(x\) of the robot pointed to by the \(h\)th hand with the given complete instruction <COMMAND>.

Advanced instructions:

  • ACTIVATE h: Activate the robot pointed to by the \(h\)th hand. Activation means executing all its instructions in order. Note that if instructions change during execution, the updated version is executed.
  • TRIGGER <COMMANDNAME>: <COMMAND>: This instruction is not executed immediately. Instead, after other robots finish executing an instruction, if their right hand points to a robot containing a pending TRIGGER command meeting certain conditions, that command is triggered and its inner <COMMAND> is executed. The conditions involve matching the just executed command's name with <COMMANDNAME> (or, if <COMMANDNAME> is TRIGGER, matching the triggered command). After being triggered and executed, control returns to the original execution order.

Execution Process:

You start by activating robots in increasing order of indices beginning from robot \(0\), then robot \(1\), and so on. Once the last robot is activated, the process repeats (i.e. in rounds) until a total of \(k\) instructions have been executed. Every time a robot executes an instruction, you should output a line of information about that execution.

In this problem, you are asked to simulate the execution process and output the information of the first \(k\) executed instructions. For each executed instruction, output a line in the form:

robot X: <instruction>

where X is the id of the robot executing the instruction and <instruction> is the instruction text.

For the purpose of this problem, all instructions not described in detail (like SWAP, MIRROR, REPLACE, and TRIGGER) can be considered as having no effect on the simulation. You only need to implement the behavior of SLACKOFF, MOVE, and ACTIVATE commands.

inputFormat

The first line contains three integers \(n\), \(m\) and \(k\) --- the number of robots, the number of instructions per robot, and the number of instructions to report, respectively.

The next \(n\) lines each contain two integers \(l_i\) and \(r_i\) (\(0 \le l_i, r_i < n\)) which denote the initial pointers for the left and right hands of robot \(i\).

This is followed by \(n \times m\) lines, each describing one instruction. The instructions for robot \(0\) come first (in order), then robot \(1\), and so on. Each instruction is one of the following formats:

  • SLACKOFF
  • MOVE h z where \(h\) is either 0 or 1 and \(z\) is a nonnegative integer.
  • ACTIVATE h where \(h\) is either 0 or 1.
  • Other commands (SWAP, MIRROR, REPLACE, TRIGGER) may appear but they do not affect the simulation.

outputFormat

Output exactly \(k\) lines, each representing an executed instruction in the order of execution. Each line should be of the form:

robot X: <instruction>

where X is the robot's index and <instruction> is the instruction text exactly as provided in the input.

sample

3 2 5
1 2
2 0
0 1
SLACKOFF
MOVE 0 1
SLACKOFF
ACTIVATE 1
MOVE 1 2
SLACKOFF
robot 0: SLACKOFF

robot 0: MOVE 0 1 robot 1: SLACKOFF robot 1: ACTIVATE 1 robot 0: SLACKOFF

</p>