#P8390. [COI 2021] MalnaRISC
[COI 2021] MalnaRISC
Problem Description
Translated from COI 2021 T4 “MalnaRISC”
You need to use the magical processor MalnaRISC to solve a well-known problem—sorting!
MalnaRISC supports only one instruction: CMPSWP . Its meaning is: compare the values in and , and if , swap them.
The most powerful feature of MalnaRISC is that it can execute multiple different instructions written on the same line at the same time, as long as they do not conflict. That is, each register used as an argument to CMPSWP can appear at most once within the same line.
Now, please write a MalnaRISC program that sorts a sequence of length (in non-decreasing order). We will score your solution based on the length of your program.
Input Format
A single line containing one integer .
Output Format
The first line contains an integer , the length of your code.
The next lines each represent one line of your code.
2
1
CMPSWP R1 R2
3
3
CMPSWP R1 R2
CMPSWP R1 R3
CMPSWP R2 R3
4
4
CMPSWP R1 R3
CMPSWP R2 R4
CMPSWP R1 R2 CMPSWP R3 R4
CMPSWP R2 R3
Hint
| Subtask | Score | ||||
|---|---|---|---|---|---|
If your correct code has lines, then you will receive the rounded score given by:
$$\text{score}(t)= \begin{cases} 0 & t>t_1\\ 1+\frac{2}{t-t_2} & t_1\ge t>t_2\\ 3+\frac{7(t_2-t+1)}{t_2-t_3} & t_2\ge t>t_3\\ 10 & t_3\ge t \end{cases}$$Translated by ChatGPT 5