Universal Cup Judging System

Universal Cup

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Difficulty: [show] Hackable ✓
Statistics

一個機械人位於二維直角坐標系上面。初始時,機械人位於 $(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.