#P16347. Wisdom, Computer Science, and the E.T.C.
Wisdom, Computer Science, and the E.T.C.
Background
Source of this problem: https://www.luogu.com.cn/contest/314899.
:::warning{open} Since the problem setter was rushing to write the problem, most of the content may be relatively simple.
If you solve it instantly, you can make a harder version. :::
::::info[Advertisement] There are many types of companies that can transport things. For example, some of them can transport food, we call them food transportation companies. Similarly, there are material transportation companies, factory transportation companies, furniture transportation companies, and the Energy Transportation Company, E.T.C.
:::align{center}
:::
Bob, one of my friends, works in E.T.C. "E.T.C. has a good working environment, excellent dining, adequate compensation, and plenty of leisure time. If you work there, when you finish all your work and walk out of the gate at 3 p.m., you will definitely feel happy and comfortable," Bob says.
Above is some introduction about E.T.C. But don't pay too much attention to the descriptions what are all fictional. The problem statement below is not related to E.T.C. or the text above. ::::
To ensure image quality, please make sure your computer has downloaded the Caviar Dreams font.
Problem Description
In some world, there is something called energy, which exists in certain materials. But unlike our world, sometimes energy can detach from matter and appear by itself. In this case, we usually use to represent the amount of energy, where is any integer.
Sometimes, some energies gather at the same place. Then these energies merge with each other to form a larger energy, and the amount of the new energy equals the sum of the amounts of all those energies.
Meanwhile, there is a company called the Energy Transportation Company, abbreviated as E.T.C. In the early days of E.T.C., its business only included energy storage transfer and energy delivery. As time went on and various supply demands increased, E.T.C. gradually became a IoT company a mature multifunctional company with a complete system.
E.T.C. has a new emerging industry: using energy to compute. Researchers invented a set of machines. Some of these machines can generate energy out of thin air, some can double energy, and some can even convert energy into negative energy of the corresponding amount.
Negative energy of amount can be understood as energy of amount . In other words, when negative energy merges with energy, they cancel each other at the same rate until one of them disappears.
A few days ago, E.T.C. purchased this set of machines.
We place all machines that are needed into the newly opened computing workshop, number the machines from to , and connect them with energy pipelines. Among them, there are some special machines that can interact with workers for input and output, making it convenient for people to operate. This set of machines and energy pipelines, which includes input, output, and computational processing, forms a structure that can handle some relatively fixed operations. We call it a program.
In a program, every machine operates at the same frequency, and we call this frequency a round. In each round, based on the sum of all energies input to it in the previous round and on the machine’s own settings, a machine outputs a certain amount of energy to one or more specific machines. We define the time when the program starts running as round , and then we can describe the operations performed by each machine at a certain time.
Let the current round number be . The input to the input machine with index in round is denoted by . The total output received by machine from other machines in round is denoted by . The operation of outputting energy of amount to machine so that it will be received by machine in the next round is denoted by .
Initially, all are .
Then, machine ’s operation in round can be divided into the following types:
| Name | Symbol | Operands | Computation |
|---|---|---|---|
| Input machine | I |
id out |
|
| Output machine | O |
None | There must be exactly one in a program. If , terminate the whole program and output as the total output of the program. It is guaranteed that the answer is not . |
| Energy-producing machine | P |
amount out |
${\begin{cases} E_{t,i} + \textrm{amount} \to \textrm{out} & E_{t,i} \ge 0 \\ \min(E_{t,i} + \textrm{amount}, 0) \to \textrm{out} & E_{t,i} < 0 \end{cases}}$ |
| Energy-reducing machine | R |
${\begin{cases} \max(E_{t,i} - \textrm{amount}, 0) \to \textrm{out} & E_{t,i} \ge 0 \\ E_{t,i} - \textrm{amount} \to \textrm{out} & E_{t,i} < 0 \end{cases}}$ | |
| Negation machine | N |
out |
|
| Copy machine | C |
out1 out2 |
, |
| Delay machine | T |
out |
It has two states: idle and working. Initially it is idle. If it is idle and , then it becomes working. In round , it switches from working back to idle, and performs: ${\begin{cases}\sum_{j = t + 1}^{t + E_{t,i}}{E_{j,i}} \to \textrm{out} & E_{t,i} > 0 \\ E_{t-E_{t,i},i} \to \textrm{out} & E_{t,i} < 0 \end{cases}}$ |
| Decision machine | D |
x1 out1 x2 out2 x3 out3 |
${\begin{cases} x_1 \to \textrm{out}_1 & E_{t,i} < 0 \\ x_2 \to \textrm{out}_2 & E_{t,i} = 0 \\ x_3 \to \textrm{out}_3 & E_{t,i} > 0 \\ \end{cases}}$ |
All parameters above must satisfy $1 \le \textrm{out}, \textrm{out}_1, \textrm{out}_2, \textrm{out}_3 \le N$, $0 \le \textrm{amount}, |x_1|, |x_2|, |x_3| \le 10^9$.
In addition, if there are required input machines, then all must satisfy , and each number in appears exactly once.
In particular, machines have an upper limit on recognition ability. If the absolute value of the total output received by machine in round is greater than , then will be rounded to the number with the same sign and absolute value .
After accumulating some experience, we found that in many cases it is hard to adjust the program structure to match the input speed. Later, we actively negotiated with clients and increased the flexibility of our input. Now we can set a positive integer input factor , which indicates how much the input is slowed down. Let the initial input matrix be . Then the actual input matrix satisfies , and all unspecified positions are .
Now we hand over the task of program design to you. You need to solve the tasks below, while keeping the number of machines and the time to produce the output small enough:
:::info[Task 1]{open} Input at , output . . :::
:::info[Task 2]{open} Input at , then input at , output . . :::
:::info[Task 3]{open} Input at and respectively, output . . :::
:::info[Task 4]{open} Input at and respectively, output . . :::
:::info[Task 5]{open} Input at , output the -th term of the sequence ${A = \{1, 1, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 12, 13\}}$, i.e., . . :::
:::info[Task 6]{open} For each integer with , input at , output . . :::
:::info[Task 7]{open} Input at , input at , then for all integers with , input at , output . , . :::
:::info[Task 8]{open} Input at , then for all integers with , input at , output . . :::
:::info[Task 9]{open} Input at , input at , then for all integers with , input at , output the smallest index such that . It is guaranteed that there exists exactly one . , . :::
Input Format
The input contains only one line with one integer, representing the index of the task to solve. In particular, in the sample, the index is .
Output Format
On the first line, output two positive integers: the number of machines you use and the input factor you specify.
In the next lines, line is used to describe machine .
When describing each machine, first output an uppercase letter indicating the type of the computing node, then output several non-negative integers as the machine parameters in the order given in the table above. Separate the uppercase letter and numbers, and numbers and numbers, with spaces.
0
2 1
I 1 2
O
Hint
The sample output is a program that outputs in round .
In the provided file wisdom.zip, we provide nine scoring files wisdom1.ans to wisdom9.ans, corresponding to the nine tasks.
Each scoring file has lines in total. Line contains two scoring parameters and . Their meanings will be given below.
In this problem, each test point is scored independently, and each test point is worth points.
If the contestant’s output has greater than , has an invalid output format, or has parameters that do not meet the requirements of the statement, then the score is .
Otherwise, the contestant’s output is judged to be correct according to the following rules:
- First, the judge generates several groups of input data, puts the input data into the matrix according to the format, and then runs the program.
- If your program still does not output an answer after running for rounds, or if the output is different from the expected output, the score is .
- Otherwise, we consider your program to have completed this task.
For each test point, we set scoring parameters: and .
When your program can complete the corresponding task, suppose your program has machines and outputs at the latest in round under the testdata. We then find the smallest such that and . Then your program gets points on this test point.
Note that because two scoring parameters take effect at the same time, to get more points you must make a trade-off between your program’s efficiency and size.
The file wisdom.zip includes a simulator simulator.cpp. The Special Judge implementation is basically the same as this file. You can check the code directly for usage, and we will not repeat it here.
Translated by ChatGPT 5