luogu#P7915. [CSP-S 2021] 回文
[CSP-S 2021] 回文
Problem Description
Given a positive integer and an integer sequence , among these numbers, each of appears exactly times. Now perform operations, with the goal of creating a sequence of the same length . Initially, is an empty sequence. Each time, you may perform one of the following two operations:
- Append the first element of sequence to the end of , and remove it from .
- Append the last element of sequence to the end of , and remove it from .
Our goal is to make a palindromic sequence, that is, it satisfies for all , . Please determine whether this goal can be achieved. If it can, output the lexicographically smallest operation plan, as explained in Output Format.
Input Format
Each test point contains multiple groups of testdata.
The first line of input contains an integer , the number of test cases. For each test case:
The first line contains a positive integer .
The second line contains space-separated integers .
Output Format
For each test case, output one line as the answer.
If it is impossible to generate a palindromic sequence, output a line -1. Otherwise, output a string of length consisting of characters L or R (with no spaces), where L means removing the first element (operation 1), and R means operation 2.
You need to output the lexicographically smallest string among all valid plans.
The lexicographical order is defined as follows: for two strings and of length , is lexicographically smaller than if and only if there exists an index such that for every , , and .
2
5
4 1 2 4 5 3 1 2 3 5
3
3 2 1 2 1 3
LRRLLRRRRL
-1
见附件中的 palin/palin2.in
见附件中的 palin/palin2.ans
Hint
Sample Explanation #1
In the first group of data, the generated sequence is , and you can see that this is a palindromic sequence.
Another possible operation plan is LRRLLRRRRR, but its lexicographical order is larger than the answer.
Constraints
Let denote the sum of over all test cases.
For all test points, it is guaranteed that , .
| Test Point ID | Special Property | |||
|---|---|---|---|---|
| None | ||||
| Yes | ||||
| None | ||||
Special Property: If each time we delete two adjacent equal numbers in , there exists a way to delete the entire sequence (for example, ).
Hack testdata provided by
@潜在了H2O下面。
Translated by ChatGPT 5