Universal Cup Judging System

Universal Cup

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100 Difficulté: [afficher] Hackable ✓
Statistiques

一個機器人位於二維直角坐標系上。初始時,機器人位於 $(0, 0)$,Yuki 希望使用一序列指令引導機器人到達 $(x, y)$。

具體來說,指令字串僅由 0 與 1 組成:

  • 0 表示向右移動一步,將機器人的位置從 $(a, b)$ 變為 $(a + 1, b)$。
  • 1 表示向上移動一步,將機器人的位置從 $(a, b)$ 變為 $(a, b + 1)$。

Yuki 有一個長度為 $n$ 的指令字串 $s = s_1 \dots s_n$,其中僅包含 0、1 和 2。Yuki 必須先將字串中的所有 2 替換為 0 或 1。接著,機器人按照以下規則運行:

  • 對於每個非負整數 $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.