#P9383. [THUPC 2023 决赛] 喵了个喵 III
[THUPC 2023 决赛] 喵了个喵 III
Background
Xiao E has gotten tired of Meow Meow Meow, so they decided to try a different match-elimination game. However, Xiao E found that most elimination games on the market have almost the same rules. For example, this game differs from Meow Meow Meow by only one character. Although changing one character makes it a new game, it still feels a bit lacking.
Problem Description
This game has one deck and stacks. The goal is to eliminate all cards following the rules. Initially, there are cards in the deck, whose patterns from top to bottom are . There are kinds of patterns in total, numbered from to . In the deck, the number of cards of each pattern is even. Initially, all stacks are empty. There are two operations in this game:
-
Choose a stack and put the top card of the deck onto the top of that stack. If after doing so, the top two cards of this stack have the same pattern, then these two cards will be eliminated automatically.
-
Choose two different stacks. If the cards at the top of these two stacks have the same pattern, then you may eliminate these two cards. If they are different, then nothing happens.
After observing many times, Xiao E found that it is always the case that and , i.e. there are only two stacks and each pattern has exactly cards. Even so, Xiao E still cannot clear the game. Please help Xiao E design a strategy for the game, i.e. output a corresponding sequence of operations so that Xiao E can eliminate all cards.
Input Format
The first line contains a positive integer .
The second line contains positive integers, denoting .
It is guaranteed that each integer in appears exactly twice in the sequence.
Output Format
This problem uses special judge.
If there is no solution, output one line No solution..
If there is a solution, output Cleared. in the first line. In the second line output a positive integer , the number of operations. You need to ensure .
Then output a string of length , one character per operation. Each character is a non-negative integer not exceeding , representing the operation performed in order. If it is 1 or 2, it means performing the first operation and choosing stack or stack . If it is 0, it means performing the second operation. Since there are only two stacks, you do not need to output extra information to specify which two stacks you choose.
4
1 2 1 2
Cleared.
5
12202
Hint
Explanation of Sample 1
The figure below shows the initial state.

The figure below shows the result after the first two operations.


The figure below shows the result after the third and fourth operations.


The figure below shows the result after the fifth operation.


Constraints
- It is guaranteed that and is even.
- It is guaranteed that , and each number appears exactly twice in the sequence.
Scoring
Your first output line must be identical to the standard answer.
If there is a solution, and after performing all operations in order, the deck is empty and all stacks are empty, then your answer is considered correct.
Postscript
The following part is unrelated to this problem.
In fact, the person who complained that the statement of Meow Meow Meow II was too long was Xiao E themself. In the original statement, the background and description were as follows:
【Background】
Xiao E has gotten tired of Meow Meow Meow, so they decided to try a different match-elimination game. However, Xiao E found that most elimination games on the market have almost the same rules. For example, this game differs from Meow Meow Meow only slightly. Although changing one character makes it a new game, it still feels a bit lacking.
【Description】
This game has one deck and stacks from which elements can be removed from the bottom. The goal is to eliminate all cards following the rules. Initially, there are cards in the deck, whose patterns from top to bottom are . There are kinds of patterns in total, numbered from to . In the deck, the number of cards of each pattern is even. Initially, all stacks are empty. There are two operations in this game:
-
Choose a stack and put the top card of the deck onto the top of that stack.
-
Choose two different stacks. If the cards at the bottom of these two stacks have the same pattern, then you may eliminate these two cards, and the cards that were originally above the bottom will become the new bottom. If they are different, then nothing happens.
After observing many times, Xiao E found that it is always the case that and , and each pattern has exactly cards. Even so, Xiao E still cannot clear the game. Please help Xiao E design a strategy for the game, i.e. output a corresponding sequence of operations so that Xiao E can eliminate all cards.
Source
From the finals of THUPC2023, Tsinghua University Student Algorithm and Programming Contest & Collegiate Invitational Contest (THUPC2023).
Resources such as solutions can be found at https://github.com/THUSAAC/THUPC2023.
Translated by ChatGPT 5