QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 1024 MB Puntuación total: 100

#10265. AB 到 C

Estadísticas

给定一个仅由字符 $A, B, C$ 组成的字符串。你可以根据需要多次执行以下操作:

  • 选择 $1 \le i < j \le |S|$ 使得 $S_i \neq S_j$。
    • 删除 $S_i$ 和 $S_j$。
    • 将 $(S_i, S_j)$ 的互补字符插入回字符串的任意位置。

$(S_i, S_j)$ 的互补字符定义如下:

  • 若 $X = (A, B)$ 或 $(B, A)$,则互补字符为 $C$。
  • 若 $X = (B, C)$ 或 $(C, B)$,则互补字符为 $A$。
  • 若 $X = (A, C)$ 或 $(C, A)$,则互补字符为 $B$。

你可以对 $S$ 执行任意次数的操作。求出操作后可能得到的字典序最小的字符串。

输入格式

  • 第一行包含一个整数 $T$,表示测试用例的数量。
  • 每个测试用例包含多行输入:
    • 第一行包含一个整数 $N$,表示字符串的长度。
    • 第二行包含一个字符串 $S$。

输出格式

对于每个测试用例,输出一行,表示应用操作后可能得到的字典序最小的字符串。

数据范围

  • $1 \le T \le 10^5$
  • $1 \le N \le 2 \cdot 10^5$
  • $S_i \in \{A, B, C\}$
  • $|S| = N$
  • 所有测试用例的 $N$ 之和不超过 $10^6$

样例

输入 1

3
2
BC
3
AAA
3
CAA

输出 1

A
AAA
AB

说明 1

测试用例 1:我们使用 $i=1, j=2$ 进行一次操作。删除 $S_1$ 和 $S_2$,字符串暂时为空。互补字符为 $A$,将其插入字符串的第 1 个位置。最终得到 $A$。

测试用例 2:无法进行任何操作。

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.