QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓

#17343. 操作机器人

統計

一个机器人位于二维直角坐标系上。初始时,机器人位于 $(0, 0)$,Yuki 希望使用一序列指令引导机器人到达 $(x, y)$。

具体来说,指令字符串仅由 01 组成:

  • 0 表示向右移动一步,将机器人的位置从 $(a, b)$ 变为 $(a + 1, b)$。
  • 1 表示向上移动一步,将机器人的位置从 $(a, b)$ 变为 $(a, b + 1)$。

Yuki 有一个长度为 $n$ 的指令字符串 $s = s_1 \dots s_n$,其中仅包含 012。Yuki 必须首先将字符串中的所有 2 替换为 01。然后,机器人按照以下规则运行:

  • 对于每个非负整数 $i$,如果机器人在时刻 $i$ 未处于 $(x, y)$,则机器人执行该字符串的第 $((i \bmod n) + 1)$ 条指令。

Yuki 希望找到一种替换方案,使得机器人能够到达 $(x, y)$,且得到的指令字符串的字典序尽可能小。你需要帮助 Yuki 找到满足条件的字典序最小的指令字符串,或者报告不存在这样的字符串。

输入格式

本题包含多个测试用例。

第一行包含一个正整数 $t$ ($1 \le t \le 10^5$),表示测试用例的数量。

对于每个测试用例:

  • 第一行包含三个整数 $n, x, y$ ($1 \le n \le 10^6$, $0 \le x, y \le 10^{18}$)。
  • 第二行包含一个长度为 $n$ 的字符串 $s$ ($s_i \in \{0, 1, 2\}$)。

保证所有测试用例中 $n$ 的总和不超过 $10^6$。

输出格式

对于每个测试用例,输出一行:

  • 如果不存在这样的指令字符串,输出 -1
  • 如果存在这样的指令字符串,输出一个长度为 $n$ 的字符串,表示字典序最小的合法指令字符串。

样例

输入样例 1

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

输出样例 1

01111
00111
-1
011001
-1
00100

说明

对于第一个测试用例:

  • 初始时,机器人位于 $(0, 0)$,且指令字符串为 01111
  • 按照规则,机器人依次移动到 $(1, 0)$、$(1, 1)$、$(1, 2)$、$(1, 3)$、$(1, 4)$、$(2, 4)$。
  • 由于机器人到达了 $(2, 4)$,因此 01111 是一个合法的指令字符串。可以证明 01111 是字典序最小的合法字符串,所以答案为 01111

对于第二个测试用例:

  • 初始时,机器人位于 $(0, 0)$,我们将指令字符串 02221 替换为 00111
  • 按照规则,机器人依次移动到 $(1, 0)$、$(2, 0)$、$(2, 1)$、$(2, 2)$、$(2, 3)$、$(3, 3)$。
  • 由于机器人到达了 $(3, 3)$,因此 00111 是一个合法的指令字符串。可以证明 00111 是字典序最小的合法字符串,所以答案为 00111

对于第三个测试用例:

  • 可以证明,无法通过替换指令字符串中的 2 使得机器人到达 $(3, 3)$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.