#P8471. [Aya Round 1 F] 琪露诺的选择题

    ID: 9571 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>洛谷原创Special JudgeO2优化构造洛谷月赛

[Aya Round 1 F] 琪露诺的选择题

Background

Problem Number: 24\textit{24}

After some training by Shameimaru Aya, Cirno’s IQ finally increased by ⑨ points.

Now the terakoya is going to have another exam. Cirno used some methods to learn part of the information about the correct answers. Also, because she is “ice-smart”, she does not want her score improvement to be too obvious, so that the teacher, Kamishirasawa Keine, will pay special attention to her. Therefore, she came to you for help.

(Note: cheating in exams is wrong!)

Problem Description

There are 2n2 \cdot n multiple-choice questions, and each question has two options: A\text{A} and B\text{B}. The correct answers can be represented as a string of length 2n2 \cdot n.

Now you need to construct an answer sheet (also a string of length 2n2 \cdot n) such that it contains exactly aa A\text{A}’s, and compared with the correct answer string, your answer sheet has exactly ee wrong answers. If no such construction exists, report that there is no solution.

Note: For easier handling, this problem guarantees ene \le n.

Formally, given n,a,en, a, e and a binary string ss of length 2n2 \cdot n, you need to construct a binary string pp of length 2n2 \cdot n that contains exactly aa characters equal to 0\texttt 0, such that

(i=12n[sipi])=e,\left(\sum_{i=1}^{2\cdot n}[s_i\ne p_i]\right)=e,

where [][] denotes the Iverson Bracket. See the “Hint” in “Notes / Hints”.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, the number of test cases.

For each test case:

  • The first line contains three integers n,a,en, a, e.
  • The second line contains a string of length 2n2 \cdot n, representing the answer string.

Output Format

Output a total of TT lines.

For each test case:

  • If there is a solution, output one line containing a string of length 2n2 \cdot n, representing the answer sheet you constructed.
  • If there is no solution, output one line containing the string -1\texttt{-1}.
2
3 2 3
ABABBA
3 3 1
AAABBB
BBAABB
-1

Hint

Sample Explanation

For test case 11, the answer sheet you construct, BBAABB\text{BB{\color{e74c3c}AA}BB}, contains exactly 22 A\text A’s, and compared with the correct answer string it differs at exactly 33 positions (i.e., there are 33 wrong answers):

$$\text{{\color{e74c3c}A}BA{\color{e74c3c}B}B{\color{e74c3c}A}}\\ \text{{\color{52c41a}B}BA{\color{52c41a}A}B{\color{52c41a}B}}$$

So it satisfies the requirements.

For test case 22, there is no valid construction.

Constraints

For 100%100\% of the data, 1T1001 \le T \le 100, 1n1051 \le n \le 10^5, 0en0 \le e \le n, 0a2n0 \le a \le 2 \cdot n.

Within a single test file, it is guaranteed that (2n)106\sum(2 \cdot n) \le 10^6.

Hint

A. Iverson Bracket\textbf{A. Iverson Bracket}

The Iverson Bracket is a notation using square brackets: if the condition inside the brackets is true, it equals 11; otherwise it equals 00. More precisely,

$$[P]=\begin{cases}1, & \text{If }P\text{ is true,}\\0,&\text{Otherwise.}\end{cases}$$

Translated by ChatGPT 5