#P17295. [ICPC 2026 Xi'an I] Operating Robot

    ID: 17186 Type: RemoteJudge 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>模拟贪心前缀和ICPC2026省赛/邀请赛西安

[ICPC 2026 Xi'an I] Operating Robot

题目描述

A robot is located on a 2D Cartesian coordinate system. Initially, the robot is at (0,0)(0,0), and Yuki wants to guide the robot to (x,y)(x,y) using a sequence of instructions.

Specifically, an instruction string consists only of 0\texttt{0} and 1\texttt{1}:

  • 0\texttt{0} represents moving one step to the right, changing the robot's position from (a,b)(a,b) to (a+1,b)(a+1,b).
  • 1\texttt{1} represents moving one step upward, changing the robot's position from (a,b)(a,b) to (a,b+1)(a,b+1).

Yuki has an instruction string s=s1…sns = s_1 \dots s_n of length nn containing only 0\texttt{0}, 1\texttt{1}, and 2\texttt{2}. Yuki must first replace all 2\texttt{2}s in the string with either 0\texttt{0} or 1\texttt{1}. Then, the robot operates according to the following rule:

  • For every non-negative integer ii, if the robot is not at (x,y)(x,y) at time ii, the robot executes the ((i mod n)+1)((i \bmod n) + 1)-th instruction of the string.

Yuki wants to find a replacement such that the robot reaches (x,y)(x,y) 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 tt (1≤t≤105)(1 \le t \le 10^5), representing the number of test cases.

For each test case:

  • The first line contains three integers n,x,yn, x, y (1≤n≤106, 0≤x,y≤1018)(1 \le n \le 10^6,\ 0 \le x,y \le 10^{18}).
  • The second line contains a string ss of length nn (si∈{0,1,2})(s_i \in \{\texttt 0,\texttt 1,\texttt 2\}).

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

输出格式

For each test case, output one line:

  • If no such instruction string exists, output −1-1.
  • If such an instruction string exists, output a string of length nn 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 (0,0)(0,0), and the instruction string is 01111\texttt{01111}.
  • Following the rules, the robot moves sequentially to (1,0),(1,1),(1,2),(1,3),(1,4),(2,4)(1,0), (1,1), (1,2), (1,3), (1,4), (2,4).
  • Since the robot reaches (2,4)(2,4), 01111\texttt{01111} is a valid instruction string. It can be proven that 01111\texttt{01111} is the lexicographically smallest valid string, so the answer is 01111\texttt{01111}. \end{itemize}

For the second test case:

  • Initially, the robot is at (0,0)(0,0), and we replace the instruction string 02221\texttt{02221} with 00111\texttt{00111}.
  • Following the rules, the robot moves sequentially to (1,0),(2,0),(2,1),(2,2),(2,3),(3,3)(1,0), (2,0), (2,1), (2,2), (2,3), (3,3).
  • Since the robot reaches (3,3)(3,3), 00111\texttt{00111} is a valid instruction string. It can be proven that 00111\texttt{00111} is the lexicographically smallest valid string, so the answer is 00111\texttt{00111}.

For the third test case:

  • It can be proven that there is no way to replace the 2\texttt{2}s in the instruction string such that the robot reaches (3,3)(3,3).