Hello 2026
G
Snake Instructions
Codeforces
3200
原题
← FH →
翻译中…

This is an interactive problem.

翻译中…

There are $n$ snakes on the number line. The $i$-th snake is located at the position $a_i$ and has a speed $s_i$. You know the position of each snake, and that the speed of each snake is an integer from $0$ to $2$ inclusive, but you do not know the exact speed of each snake. It is guaranteed that no two snakes are at the same position.

翻译中…

To figure out the snakes' speed, you may give up to $3$ instructions. Each instruction should be given in the form of a binary string of length $m$ containing letters L and R ($1 \leq m \leq 4n$). After receiving this instruction, the snakes will move for $m$ seconds. On the $i$-th second, if $s_i=$L, then all snakes move left for that second. Otherwise, all snakes move right for that second. If two snakes are at the same location at any given point (including if the time is not an integer number of seconds), the faster snake is removed from the board. After all $m$ seconds have passed, you are given the number of remaining snakes, as well as the location of all remaining snakes. Note that each instruction is independent of each other – that means that all snakes are revived and moved to their original positions.

翻译中…

Your task is to find the speed of all snakes. However, it may be the case that it is impossible to find the speed of at least one snake. If this is the case, you must report -1 instead. You should only output -1 if it is impossible to figure out the speed of at least one snake, no matter which instructions are given. If you report -1 when there are a series of at most $3$ instructions that will uniquely determine the speed of each snake, you will get the Wrong Answer verdict. Similarly, you will receive the Wrong Answer verdict if you did not report -1 when the configuration is impossible to determine, even if you correctly guessed the speeds.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.

翻译中…

The first line of each test case contains an integer $n$ – the number of snakes ($2 \leq n \leq 10^5$).

翻译中…

The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \leq a_1 \lt a_2 \lt \ldots \lt a_n \leq 4n$) – the initial position of all snakes.

翻译中…

It is guaranteed that the sum of $n$ across all test cases does not exceed $10^5$.

翻译中…

Interaction

翻译中…

After reading in the position of all snakes, interaction begins. To give an instruction, output a line in the following format:

翻译中…
  • ? s
翻译中…

You should guarantee that $s$ contains only letters L and R, and has length between $1$ and $4n$ inclusive.

翻译中…

The jury will return a line in the following format:

翻译中…
  • $k\:b_1\:b_2\:\ldots\:b_k\:(1 \leq k \leq n, -10^9 \leq b_1 \lt b_2 \lt \ldots \lt b_k \leq 10^9$)
翻译中…

Here, $k$ is the number of snakes that remain after the full instruction, and $b_1,b_2,\ldots,b_k$ are their final positions.

翻译中…

When you are ready to output the answer, output a line in the following format:

翻译中…
  • If it is impossible to determine the speed of all snakes, output ! -1
  • Otherwise, output ! $s_1$ $s_2$ $\ldots$ $s_n$ ($0 \leq s_i \leq 2$). Here, $s_i$ should denote the speed of the $i$-th snake as given in the input.
翻译中…

Printing the answer does not count as giving an instruction.

翻译中…

After this, proceed to the next case or terminate the program if this is the last test case.

翻译中…

The interactor is not adaptive. This means that the speed of all snakes is fixed in advance and does not change in the interaction process. It is further guaranteed that there exists a solution – that is, the resulting positions of all snakes after movements are consistent with their speeds.

翻译中…

After printing each query do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict.

翻译中…

If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

翻译中…

Hacks

翻译中…

To make a hack, use the following format:

翻译中…

$^{\text{∗}}$To flush, use: fflush(stdout) or cout.flush() in C++; sys.stdout.flush() in Python; see the documentation for other languages.

翻译中…

Note

翻译中…

In the first test case, the speed of the snakes is $0$ and $1$. The program begins by giving the instruction L. The right snake moves from $2$ to $1$ while the left snake does not move. However, since now both snakes occupy the position $1$, the one with the higher speed (the right snake) is removed. Therefore, there is only one snake remaining, and it is at position $1$. At this point, the program decides to guess the speed of snakes as $0$ and $1$, which is correct, so this test case is passed. Note that although the speeds $[0,2]$ would also result in there being $1$ snake at position $1$ at the end, we cannot report $-1$, as we can show there is a series of instructions that will differentiate $[0,2]$ and $[0,1]$.

翻译中…

In the third test case, we conclude that the speed of both the first snake and the third snake is $0$, and we can show there is no way to differentiate the speed of the middle snake between $1$ and $2$. Therefore, reporting -1 is correct in this case.

翻译中…

样例

Input #1
7
2
1 2

1 1

2
1 6

2 1 4

3
2 3 4

2 2 4

3
2 3 4

3 5 6 7

5
1 3 8 14 15

5
1 2 3 4 5

4
5 6 7 8
Output #1
? L

! 0 1

? LRLL

! 0 1

? RRR

! -1

? RRR

! 1 1 1

! 2 1 0 0 1

! 0 2 2 2 0

! 0 1 2 0
InputCopy OutputCopy
题目信息
题号
2183G
所属比赛
时间限制
3 s
内存限制
256 MB
标签
构造
贪心
交互题

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。