#P15783. [JAG 2025 Summer Camp #3] Ants Collision
[JAG 2025 Summer Camp #3] Ants Collision
题目描述
There are ants on a number line. The -th ant is initially at coordinate and is stationary. Each ant faces either right (the positive direction) or left (the negative direction), but the initial directions are unknown.
At time , each ant starts moving at a speed of per unit time. Whenever two ants collide (i.e., occupy the same position), they turn around and move in the opposite direction.
By time , the -th ant has collided with other ants exactly times.
Determine whether there exists an assignment of initial directions for the ants that is consistent with these collision counts. If such an assignment exists, construct one.
输入格式
The input consists of multiple test cases.
The first line contains an integer (), representing the number of test cases.
test cases follow. Each test case is given in the following format.
$$\begin{aligned} &N \\ &A_1 \ A_2 \ \ldots \ A_N \end{aligned} $$For each test case, the first line contains an integer (), representing the number of ants.
The next line contains integers (), each representing the number of times the corresponding ant has collided with other ants by time .
Additionally, the sum of over all test cases does not exceed .
输出格式
Output lines. For each test case, determine whether there exists an assignment of initial directions for the ants that satisfies the conditions described in the problem.
- If no such assignment exists, output "No".
- If an assignment exists, output a string of length consisting of characters 'L' and 'R', where the -th character is 'L' if the -th ant initially faces left (the negative direction), and 'R' if it initially faces right (the positive direction).
If multiple assignments exist, any of them will be accepted.
3
3
1 2 1
5
3 1 4 1 5
4
0 0 0 0
RRL
No
LLLL