#P80. [CSP-S 2021] Palindromic deque
[CSP-S 2021] Palindromic deque
Person in Charge
Problem Description
Given a positive integer and an integer sequence , each integer from to appears exactly twice in these numbers. We perform operations with the aim of constructing a sequence of length . Initially, the sequence is empty, and you may choose one of the following two operations in each step:
- 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, i.e., satisfy for all . You need to judge whether this goal can be achieved. If feasible, output the lexicographically smallest operation scheme, the details of which are specified in the 【Output Format】 section.
Input Format
Each test point contains multiple test cases.
The first line of input contains an integer , representing the number of test cases. For each test case:
- The first line contains a positive integer .
- The second line contains integers separated by spaces.
Output Format
Output one line of answer for each test case.
If it is impossible to generate a palindromic sequence, output a single line with -1. Otherwise, output a single line with a string of length composed of characters L or R (without spaces), where L denotes Operation 1 (removing the first element) and R denotes Operation 2 (removing the last element).
You are required to output the lexicographically smallest string among all valid schemes.
The rule for lexicographical comparison is as follows: A string of length is lexicographically smaller than a string of the same length if and only if there exists an index such that for all and .
Samples
2
5
4 1 2 4 5 3 1 2 3 5
3
3 2 1 2 1 3
LRRLLRRRRL
-1
Sample (1) Explanation
In the first group of data, the generated sequence is , which is clearly a palindromic sequence.
Another possible operation scheme is LRRLLRRRRR, which is lexicographically larger than the answer scheme.
Sample (2)
See palin/palin2.in and palin/palin2.ans in the contestant's directory.
Data Range
Let denote the sum of values across all test cases.
All test cases satisfy , .
| Test Case No. | Special Property | |||
|---|---|---|---|---|
| None | ||||
| Exists | ||||
| None | ||||
Special Property: There exists a way to erase the entire sequence by repeatedly deleting two adjacent and equal numbers from (e.g., ).