#P2682. 土豆田
土豆田
Description
Daning’s potato field works at the granularity of plots. The set of all potatoes in a plot is called a processing unit. Each processing unit can store two values: key and tmp, both are 32-bit signed integers. Each unit can execute several commands. Daning will power the processing units one by one by riding his bicycle. The order is shown in the figure below; it shows a potato field split into processing units:

The unit number is the power-on order. Each time, units are visited in order from No. to No. .
Each complete traversal is called one cycle.
Only when the potatoes in a plot are powered will they work and execute commands. After all commands finish, Daning will stop supplying power.
For each processing unit, the command formats are as follows:
inRead a number and store it into this unit’s . (If there is already a number in , it is overwritten; the same applies to all stores below.)outOutput the current unit’s .swapSwap this unit’s and .add XAdd to . can only be a constant or ; same below.set XSet to .oppNegate .revBitwise NOT on .L/R XLeft/Right shift by bits.get u/d/l/rRead the of the unit above (u) / below (d) / left (l) / right (r) and copy it into this unit’s . Neighbor positions follow the picture above.or/and/xor XBitwise OR/AND/XOR with .waitWait during this power-on period; i.e., do nothing.if XIf (can only be or ) is not equal to , then during the next time this unit is powered, execute the next instruction; otherwise skip the next instruction and execute the one after that (if it exists).goto YDuring the next time this unit is powered, start execution from instruction No. . must be a constant.endForcibly end the commands of all processing units, ignoring all remaining unexecuted commands.
We provide check.exe. Put your potato program potato.out and the input testdata you want to use potato.in in the same folder as check.exe. After running, you can view the detailed running status of your program in report.txt.
We also provide another sample potato program example2.out, a potato program using processing units that computes times an integer . You can read it yourself (this sample is not the optimal solution for that computation; it is only to demonstrate the commands).
Below is a processing unit layout. Not all units must be used.

You have the following tasks to complete by writing potato programs:
| ID | Input | Output | Constraints | Processing Unit Size Limit | Score | Additional Notes |
|---|---|---|---|---|---|---|
| None | ||||||
| Compute the absolute value of . | ||||||
| integers | None | |||||
| $\\lvert a \\rvert, \\lvert b \\rvert \\le 2.1 \\times 10^9$ | ||||||
| denotes the number of s in the binary representation of . | ||||||
| None | ||||||
| $f(n) = \\begin{cases} 1 & n < 2 \\\\ f(n-1) + f(n-2) & n \\ge 2 \\end{cases}$ |
Input Format
This is an output-only problem.
Output Format
The first line contains and , indicating you used rows and columns.
Then there are sections. In the -th section, the first line contains , the number of commands in the -th processing unit (can be ). The next lines each describe a command, as described above.
例:一个使用1*1的土豆田处理单元(下称处理单元)的A+B problem
输入两个整数a,b,|a|,|b|<=10^9
输出a+b
1 1
5
in
swap
in
add tmp
out
解释:
第一行的1 1表示用的处理单元为1*1
第二行表示第一个处理单元有5条指令。
第三行的命令在第一个周期执行,读入了一个数(假定为a) ,此时该单元的状态为key=0,tmp=a
第四行在第二个周期执行,交换了key和tmp,状态为key=a,tmp=0
第五行在第三个周期执行,读入了另一个数b,状态为key=a,tmp=b
第六行在第四个周期执行,给key加上tmp,状态为key=a+b,tmp=b
第七行在第五个周期执行,输出该单元的key,即输出了a+b
Hint
Explanation of Sample #1
This sample implements the A+B problem.
The first line 1 1 indicates the processing unit size is .
The second line indicates there are instructions in the first processing unit.
The command on the third line executes in the first cycle and reads a number (assume it is ). At this time, the unit’s state is .
The fourth line executes in the second cycle and swaps and . The state becomes .
The fifth line executes in the third cycle and reads another number . The state is .
The sixth line executes in the fourth cycle and adds to . The state is .
The seventh line executes in the fifth cycle and outputs this unit’s , i.e., it outputs .
If your program does not finish within cycles, or has a syntax error, or exceeds the processing unit size limit, you get points.
If your program for task produces the correct result, and the number of cycles required is the same as or fewer than the standard solution, you get full points for that test point. Otherwise, suppose your program ran for cycles and the standard solution ran for cycles. Your score is $\\left\\lfloor \\text{(points for that test point)} \\times \\left( \\dfrac{s}{a} \\right) \\times 0.8 \\right\\rfloor$. Note that even if it shows WA for partially correct solutions, you still receive points.
P1=7
P2=9
P3=12
P4=12
P5=13
P6=13
P7=14
P8=20
PS: If you craft any fun potato programs (they can be unrelated to the tasks in this problem), please reply under the Q&A blog or send me a private message. Rewards will be given at my discretion.
Check download is available in the attachment.
example2.out:
2 2 8 in add tmp
L 3 get r add tmp
get d add tmp
out 3 wait get l add tmp
3 wait get u add tmp
Translated by ChatGPT 5
京公网安备 11011102002149号