#P7209. [COCI 2020/2021 #3] Knjige
[COCI 2020/2021 #3] Knjige
Description
Tin thinks that books being placed out of order is the most annoying thing. Ante decides to help him. During sorting, in each step, he can do one of the following two operations:
- If the corresponding hand is empty, he may take the top book from a pile and hold it in his left hand or right hand.
- Put a book that he is holding onto the top of a bookshelf.
Ante wants you to find a method that makes the books on the left bookshelf correspond, from top to bottom, to thickness from thin to thick.
Input Format
The first line contains an integer , which denotes the number of books on the left bookshelf.
The second line contains integers , in order from top to bottom, describing the thickness of the books.
Output Format
The first line outputs an integer , which denotes the number of operations required by your method.
The next lines should be output in the format INSTRUCTION HAND SHELF:
INSTRUCTION: if Ante should take the top book from a bookshelf, outputUZMI; if he should place a book onto the top of a bookshelf, outputSTAVI.HAND: if using the left hand, outputL, otherwise outputDfor using the right hand.SHELF: if it involves the left bookshelf, outputL, otherwise outputDfor involving the right bookshelf.
Your solution does not necessarily need to use the minimum number of operations, but the total number of operations must not exceed . It can be proven that under the given conditions, there is always at least one valid solution.
3
2 3 1
8
UZMI L L
STAVI L D
UZMI L L
UZMI D L
STAVI L L
UZMI L D
STAVI L L
STAVI D L
4
1 1 2 5
0
Hint
Sample 1 Explanation

Constraints
For of the testdata, , , .
Notes
The score for this problem follows the original COCI settings, with a full score of .
This problem uses a self-written unofficial Special Judge. Everyone is welcome to hack it (you may PM or post directly). Note that the Special Judge is sensitive to the output format, so please do not output extra spaces at the end of each line.
Translated from COCI2020-2021 CONTEST #3 T1 Knjige.
Translated by ChatGPT 5
京公网安备 11011102002149号