luogu#P5207. [WC2019] 远古计算机
[WC2019] 远古计算机
Background
Penguin Continent is a magical land. Beneath the thick ice lies a huge treasure. The explorer penguin Doudou dug through the ice and reached the treasury, but then he found a troubling problem. There are five vaults in total, and each vault is controlled by some ancient computers. Because they are so old, the programs inside these computers have already disappeared. Only by rewriting code for these computers, running it successfully, and producing the correct output can the door-opening mechanism be triggered.
Problem Description
Each vault gate is controlled by a computer cluster. The computers are connected by data cables to transmit data. However, many cables are broken, so only some connections remain. At the beginning, there is no data on any cable. When a computer writes to a cable, there will be an integer on that cable. Each cable can transmit at most one integer at the same time. After the integer is read, it disappears and the cable returns to the no-data state.
Each ancient computer has two storage cells, named and . Each cell can store an integer from to .
At each moment, each ancient computer can execute one instruction. The instruction types are as follows:
mov reg val: set the value of storage cellregto the value ofval;add reg val: add the value ofvalto storage cellreg;dec reg val: subtract the value ofvalfrom storage cellreg;mul reg val: multiply storage cellregby the value ofval;div reg val: divide storage cellregby the value ofval; this division is truncation toward zero, e.g. ;and reg val: bitwise AND storage cellregwith the value ofval;or reg val: bitwise OR storage cellregwith the value ofval;xor reg val: bitwise XOR storage cellregwith the value ofval;jmp val: jump to theval-th statement of the whole program. Statements are counted from the beginning of the program starting at ;jz reg val: if the value ofregis , jump to lineval;jnz reg val: if the value ofregis not , jump to lineval;jgz reg val: if the value ofregis strictly greater than , jump to lineval;jsz reg val: if the value ofregis strictly less than , jump to lineval;read x reg: read a number from ancient computer into storage cellreg. If there is a cached number on the cable, read it and return; otherwise, wait and try again in the next cycle. When , it is considered reading one number from standard input;write val x: write the value ofvalonto the cable in the direction of ancient computer . This succeeds if and only if there is no data currently stored on the cable; otherwise, wait and try again in the next cycle. When , it is considered writing one number to standard output.
reg denotes a storage cell, and can only be or .
val denotes the value of a storage cell or a number. For example, writing means the value stored in , and writing means the number .
In the read/write instructions of an ancient computer, is considered a valid instruction only if is directly connected to the current ancient computer by a data cable, or .
Each ancient computer has independent standard input and standard output. Different ancient computers do not affect each other. That is, each ancient computer has its own independent standard input port and standard output port.
In each cycle, all ancient computers that need to execute write instructions are processed first, then those that need to execute read instructions, and finally those that need to execute other instructions.
When reading, if there is no more data available from standard input, the ancient computer will enter an eternal waiting state.
If an ancient computer finishes executing the last instruction, it will restart from the first instruction.
If an ancient computer has no instructions at all, it will stay in an eternal waiting state.
Instruction indices are positive integers starting from .
Each data cable can buffer at most one piece of data. Between two computers there is only one data cable, so it is possible to read the data written by itself in the previous round. If the two endpoint ancient computers read from or write to the same cable at the same time, the result will be unpredictable.
There is no way to write to standard input, and there is no way to read from standard output.
For example, the following sample reads two numbers from the standard input of computer , and outputs the sum of the two numbers to the standard output of computer .
node 1
read 0 a
read 0 b
write a 2
write b 2
node 2
read 1 a
read 1 b
add a b
write a 0
The following is incorrect:
node 1
read 0 a
read 0 b
add a b
write a 0
node 2
mov a a
Because in the correct answer, the standard output of ancient computer is empty, while the standard output of ancient computer is the sum of the two numbers.
Subtasks
Subtask 1
The standard input of ancient computer will contain no more than non-negative integers. Output them in the original order to the output of ancient computer .
Subtask 2
Ancient computer will receive one non-negative integer . Output the -th term of the Fibonacci sequence to the standard output of node in the original input order. The input guarantees that the -th term is at most . The Fibonacci sequence is defined as .
Subtask 3
The standard input of ancient computer will contain no more than non-negative integers. Output them in the original order to the output of ancient computer .
Subtask 4
Ancient computers to each input one number. Output these numbers from ancient computers to . The output order is arbitrary, and each ancient computer may output any number of values.
Subtask 5
Ancient computers to each input one number. Output these numbers correspondingly from ancient computers to . That is, the number input at node must be output from node .
Input Format
This is an output-only problem. There are groups of input data, named oldcomputer1.in to oldcomputer5.in.
These files describe the connection status between the ancient computers.
The first line of the file contains three non-negative integers and , representing the test point ID, the number of ancient computers, and the number of cables between them. The ancient computers are numbered from to .
The next lines each contain two positive integers , indicating that computer and computer are directly connected by a data cable.
Output Format
For each group of input data, you need to submit the corresponding output file oldcomputer1.out to oldcomputer5.out.
These files describe the code content for each ancient computer.
A file consists of multiple code blocks. The format of each code block is as follows:
The first line contains a string node and an integer between and , separated by a space, indicating that the following instructions belong to computer .
The following lines are the specific instructions of that computer.
Each computer's instruction block should appear at most once; otherwise, unknown errors may occur.
The total number of instruction lines for all computers must not exceed .
Hint
Scoring
For each test point, there are three parameters .
If the submitted code outputs the correct answer within cycles, you will get of the score for that test point.
If the submitted code outputs the correct answer within cycles, you will get of the score for that test point.
If the submitted code outputs the correct answer within cycles, you will get of the score for that test point.
That is, at the end of each cycle, the answer will be checked once, and the earliest correct check result will be used.
Subtask Scores
| Subtask ID | |||||
|---|---|---|---|---|---|
| CTT score | |||||
| Non-CTT score | |||||
Notes
Thanks to @tiger2005 for providing the spj. For how to use the spj, please refer to these two discussion posts:
Translated by ChatGPT 5