QOJ.ac

QOJ

총점: 100 출력 전용

#188. Ancient Computer

통계

This is an answer-submission problem.

Description

Each treasure vault door is controlled by a cluster of computers, which are connected by data lines to transmit data. However, many data lines are damaged, leaving only a portion of the connections. Initially, there is no data on the data lines. When a computer writes to a data line, an integer is placed on it. Each data line can transmit at most one integer at a time; once the integer is read, it disappears, and the data line returns to an empty state.

Each ancient computer has two storage units, named a and b. Each storage unit can store an integer between $-2147483648$ and $2147483647$.

At each time step, every ancient computer can execute one instruction. The available instructions are as follows:

  • mov reg val: Assign the value of val to storage unit reg.
  • add reg val: Add the value of val to storage unit reg.
  • dec reg val: Subtract the value of val from storage unit reg.
  • mul reg val: Multiply storage unit reg by the value of val.
  • div reg val: Divide storage unit reg by the value of val. This division is truncated towards zero, e.g., $\frac{-5}{2} = -2$.
  • and reg val: Perform a bitwise AND between storage unit reg and the value of val.
  • or reg val: Perform a bitwise OR between storage unit reg and the value of val.
  • xor reg val: Perform a bitwise XOR between storage unit reg and the value of val.
  • jmp val: Jump to the val-th statement of the program. Statements are counted starting from 1 at the beginning of the program.
  • jz reg val: If the value of reg is 0, jump to line val.
  • jnz reg val: If the value of reg is not 0, jump to line val.
  • jgz reg val: If the value of reg is strictly greater than 0, jump to line val.
  • jsz reg val: If the value of reg is strictly less than 0, jump to line val.
  • read x reg: Read a number from ancient computer x into storage unit reg. If a number is cached on the data line, read it and return; otherwise, wait until the next cycle to try reading again. If $x = 0$, it is treated as reading a number from standard input.
  • write val x: Write the value of val to the data line connected to ancient computer x. The write succeeds if and only if there is no data currently on the line; otherwise, wait until the next cycle to try writing again. If $x = 0$, it is treated as writing a number to standard output.

reg represents a storage unit, which must be either a or b. val represents the value of a storage unit or a number, e.g., entering a refers to the value stored in a, while entering 233 refers to the number 233.

An ancient computer's read/write instruction is considered valid only if x is directly connected to the current computer via a data line, or if $x = 0$.

Each ancient computer has independent standard input and output; computers do not affect each other, meaning each computer has its own dedicated standard input and output port.

During each cycle, all ancient computers that need to execute a write instruction calculate first, followed by those that need to execute a read instruction, and finally those executing other instructions.

During a read operation, if there is no data available to be read from standard input, the computer will enter a state of permanent waiting.

If an ancient computer finishes executing the last instruction, it will restart from the first instruction. If an ancient computer has no instructions, it will remain in a waiting state forever.

Instruction counting is based on positive integers starting from 1.

A data line can hold at most one piece of data at a time. There is only one data line between any two computers, meaning it is possible to read data written by oneself in the previous round. If computers at both ends attempt to read or write to the same data line simultaneously, the result is unpredictable.

There is no method to write to standard input or read from standard output.

Input

This is an answer-submission problem with 5 sets of input data, named oldcomputer1.in ~ oldcomputer5.in. These files describe the connection status between the ancient computers. The first line of each file contains three non-negative integers: the test case ID, the number of computers $n$, and the number of connections $m$. Computers are labeled from 1 to $n$. The following $m$ lines each contain two positive integers $x, y$, indicating that computer $x$ and computer $y$ are directly connected by a data line.

Output

For each input file, you need to submit the corresponding output file oldcomputer1.out ~ oldcomputer5.out. These files describe the code for each ancient computer. The file consists of multiple code blocks, each formatted as follows: The first line contains the string node followed by an integer $a$ between 1 and $n$, separated by a space, indicating that the following lines are instructions for computer $a$. The subsequent lines contain the specific instructions for that computer. Each computer's instructions should appear at most once; otherwise, an unknown error will occur. The total number of instructions across all computers must not exceed $10^6$ lines.

Subtasks

Subtask 1: Computer 1 receives no more than 100 non-negative integers from standard input and outputs them to its standard output in the original order.

Subtask 2: Computer 1 receives a non-negative integer $k$ from standard input and outputs the $k$-th term of the Fibonacci sequence to its standard output in the original order. The input guarantees the $k$-th term does not exceed $10^9$. The Fibonacci sequence is defined as $F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n-2}$ for $n \ge 2$.

Subtask 3: Computer 1 receives no more than 100 non-negative integers from standard input and outputs them to the standard output of computer $n$ in the original order.

Subtask 4: Computers 1 through 50 each receive one number as input. Output these 50 numbers from computers 51 through 100. The output order is arbitrary, and each computer can output any number of integers.

Subtask 5: Computers 1 through 10 each receive one number as input. Output these numbers from computers 100 through 91, respectively; i.e., the number input to computer $i$ must be output from computer $101 - i$.

Examples

Input 1

(input data)

Output 1

node 1
read 0 a
read 0 b
write a 1
write b 1
node 2
read 1 a
read 1 b
add a b
write a 0

Note

The following is an example of an incorrect implementation:

node 1
read 0 a
read 0 b
add a b
write a 0
node 2
mov a a

In the correct answer, computer 1's standard output is empty, while computer 2's standard output contains the sum of the two numbers.


또는 파일을 하나씩 업로드:

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.