#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 4×44 \times 4 processing units:

The unit number is the power-on order. Each time, units are visited in order from No. 11 to No. n×mn \times m.

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:

  1. in Read a number and store it into this unit’s texttmp\\text{tmp}. (If there is already a number in texttmp\\text{tmp}, it is overwritten; the same applies to all stores below.)
  2. out Output the current unit’s textkey\\text{key}.
  3. swap Swap this unit’s textkey\\text{key} and texttmp\\text{tmp}.
  4. add X Add XX to textkey\\text{key}. XX can only be a constant or texttmp\\text{tmp}; same below.
  5. set X Set textkey\\text{key} to XX.
  6. opp Negate textkey\\text{key}.
  7. rev Bitwise NOT on textkey\\text{key}.
  8. L/R X Left/Right shift textkey\\text{key} by XX bits.
  9. get u/d/l/r Read the textkey\\text{key} of the unit above (u) / below (d) / left (l) / right (r) and copy it into this unit’s texttmp\\text{tmp}. Neighbor positions follow the picture above.
  10. or/and/xor X Bitwise OR/AND/XOR textkey\\text{key} with XX.
  11. wait Wait during this power-on period; i.e., do nothing.
  12. if X If XX (can only be textkey\\text{key} or texttmp\\text{tmp}) is not equal to 00, 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).
  13. goto Y During the next time this unit is powered, start execution from instruction No. YY. YY must be a constant.
  14. end Forcibly 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 2×22 \times 2 processing units that computes 1010 times an integer aa. 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 1×31 \times 3 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
11 a,ba, b bab - a lvertarvert,lvertbrvertle109\\lvert a \\rvert, \\lvert b \\rvert \\le 10^9 1times31 \\times 3 77 None
22 aa 233timesa233 \\times a 1lelvertarvertle1071 \\le \\lvert a \\rvert \\le 10^7 2times22 \\times 2 99
33 lvertarvert\\lvert a \\rvert 1lelvertarvertle1091 \\le \\lvert a \\rvert \\le 10^9 1212 Compute the absolute value of aa.
44 128128 integers aia_i sumi=1128ai\\sum_{i=1}^{128} a_i 1lelvertairvertle2times1061 \\le \\lvert a_i \\rvert \\le 2 \\times 10^6 4times24 \\times 2 None
55 a,ba, b leftlfloordfraca+b2rightrfloor\\left\\lfloor \\dfrac{a + b}{2} \\right\\rfloor $\\lvert a \\rvert, \\lvert b \\rvert \\le 2.1 \\times 10^9$ 2times22 \\times 2 1313
66 aa operatornamepopcount(a)\\operatorname{popcount}(a) lvertarvertle109\\lvert a \\rvert \\le 10^9 operatornamepopcount(a)\\operatorname{popcount}(a) denotes the number of 11s in the binary representation of aa.
77 a,ba, b max(a,b)\\max(a, b) lvertarvert,lvertbrvertle109\\lvert a \\rvert, \\lvert b \\rvert \\le 10^9 1414 None
88 nn f(n)f(n) 1lenle421 \\le n \\le 42 3times33 \\times 3 2020 $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 nn and mm, indicating you used nn rows and mm columns.

Then there are ntimesmn \\times m sections. In the ii-th section, the first line contains tit_i, the number of commands in the ii-th processing unit (can be 00). The next tit_i 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 1times11 \\times 1.

The second line indicates there are 55 instructions in the first processing unit.

The command on the third line executes in the first cycle and reads a number (assume it is aa). At this time, the unit’s state is textkey=0,texttmp=a\\text{key} = 0, \\text{tmp} = a.

The fourth line executes in the second cycle and swaps textkey\\text{key} and texttmp\\text{tmp}. The state becomes textkey=a,texttmp=0\\text{key} = a, \\text{tmp} = 0.

The fifth line executes in the third cycle and reads another number bb. The state is textkey=a,texttmp=b\\text{key} = a, \\text{tmp} = b.

The sixth line executes in the fourth cycle and adds texttmp\\text{tmp} to textkey\\text{key}. The state is textkey=a+b,texttmp=b\\text{key} = a + b, \\text{tmp} = b.

The seventh line executes in the fifth cycle and outputs this unit’s textkey\\text{key}, i.e., it outputs a+ba + b.

If your program does not finish within 20002000 cycles, or has a syntax error, or exceeds the processing unit size limit, you get 00 points.

If your program for task ii 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 aa cycles and the standard solution ran for ss 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