#P2682. Potato Program Simulation
Potato Program Simulation
Potato Program Simulation
In a potato field, the field is divided into several processing units that are arranged in a grid. Each processing unit stores two 32-bit signed integers: a key and a temporary buffer tmp. A potato program can execute various commands on these units (such as in
, out
, swap
, add X
, set X
, opp
, rev
, L/R X
, get u/d/l/r
, or/and/xor X
, wait
, if X
, goto Y
, end
). The commands are broadcast so that on each power cycle only one plot (with its arranged processing units) is active. The commands are executed in the order of the processing unit numbers (for example, in a 4×4 grid as shown in the figure, process unit numbers follow the supply order from 1 to 16).
Below is a table of tasks that you can implement using the potato program. Note that while the potato program supports many commands, you are asked to implement exactly one of the following tasks based on the input:
Task No. | Input | Output | Constraints | Grid Size | Score | Note |
---|---|---|---|---|---|---|
1 | a, b | b - a | |a|, |b| ≤ 109 | 1 × 3 | 7 | None |
2 | a | 233 × a | 1 ≤ |a| ≤ 107 | 2 × 2 | 9 | None |
3 | a | |a| | 1 ≤ |a| ≤ 109 | 2 × 2 | 12 | Compute the absolute value of a |
4 | 128 integers ai | ∑i=1128 ai | 1 ≤ |ai| ≤ 2 × 106 | 4 × 2 | 12 | None |
5 | a, b | \(\lfloor \frac{a+b}{2} \rfloor\) | |a|, |b| ≤ 2.1 × 109 | 2 × 2 | 13 | None |
6 | a | popcount(a) | |a| ≤ 109 | 2 × 2 | 13 | popcount(a) is the number of 1's in the binary representation of a |
7 | a, b | max(a, b) | |a|, |b| ≤ 109 | 2 × 2 | 14 | None |
8 | n | f(n) | 1 ≤ n ≤ 42 | 3 × 3 | 20 | \(f(n)=\begin{cases}1 &\text{if } n<2,\\f(n-1)+f(n-2) &\text{if } n\ge2\end{cases}\) |
Input Format: The first integer in the input specifies the task number (an integer from 1 to 8). The rest of the input is task-dependent as detailed in the table above.
Output Format: Output a single integer result according to the selected task.
Note: Although the backstory uses the concept of a potato field with processing units and commands, you are only required to simulate the computation as described for the corresponding task.
inputFormat
The input begins with an integer task
(1 ≤ task ≤ 8). Based on the value of task
, the input format is as follows:
- If task = 1: a line containing two integers
a
andb
. - If task = 2: a line containing one integer
a
. - If task = 3: a line containing one integer
a
. - If task = 4: a single line or multiple lines containing exactly 128 integers.
- If task = 5: a line containing two integers
a
andb
. - If task = 6: a line containing one integer
a
. - If task = 7: a line containing two integers
a
andb
. - If task = 8: a line containing one integer
n
.
outputFormat
Print a single integer which is the result of the computation corresponding to the selected task.
sample
1
3 10
7