#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 RiR_i RjR_j. Its meaning is: compare the values in RiR_i and RjR_j, and if Ri>RjR_i>R_j, 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 NN (in non-decreasing order). We will score your solution based on the length of your program.

Input Format

A single line containing one integer NN.

Output Format

The first line contains an integer tt, the length of your code.

The next tt 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 NN t1t_1 t2t_2 t3t_3 Score
11 88 2828 1212 66 1010
22 1313 7878 2222 1010
33 1616 120120 2828
44 3232 496496 6060 1515
55 5353 13781378 102102 2121
66 6464 20162016 124124
77 7373 26282628 142142 2828
88 8282 33213321 160160
99 9191 40954095 178178 2929
1010 100100 49504950 196196 3030

If your correct code has tt 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