#P17295. [ICPC 2026 Xi'an I] Operating Robot
[ICPC 2026 Xi'an I] Operating Robot
题目描述
A robot is located on a 2D Cartesian coordinate system. Initially, the robot is at , and Yuki wants to guide the robot to using a sequence of instructions.
Specifically, an instruction string consists only of and :
- represents moving one step to the right, changing the robot's position from to .
- represents moving one step upward, changing the robot's position from to .
Yuki has an instruction string of length containing only , , and . Yuki must first replace all s in the string with either or . Then, the robot operates according to the following rule:
- For every non-negative integer , if the robot is not at at time , the robot executes the -th instruction of the string.
Yuki wants to find a replacement such that the robot reaches and the resulting instruction string is lexicographically as small as possible. You need to help Yuki find the lexicographically smallest instruction string that satisfies the condition, or report that no such string exists.
输入格式
This problem contains multiple test cases.
The first line contains a positive integer , representing the number of test cases.
For each test case:
- The first line contains three integers .
- The second line contains a string of length .
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output one line:
- If no such instruction string exists, output .
- If such an instruction string exists, output a string of length representing the lexicographically smallest valid instruction string.
6
5 2 4
01111
5 3 3
02221
5 3 3
00022
6 1 0
011201
4 8 7
2020
5 0 0
22102
01111
00111
-1
011001
-1
00100
提示
For the first test case:
- Initially, the robot is at , and the instruction string is .
- Following the rules, the robot moves sequentially to .
- Since the robot reaches , is a valid instruction string. It can be proven that is the lexicographically smallest valid string, so the answer is . \end{itemize}
For the second test case:
- Initially, the robot is at , and we replace the instruction string with .
- Following the rules, the robot moves sequentially to .
- Since the robot reaches , is a valid instruction string. It can be proven that is the lexicographically smallest valid string, so the answer is .
For the third test case:
- It can be proven that there is no way to replace the s in the instruction string such that the robot reaches .