AtCoder Grand Contest 066
翻译中…
Problem Statement
翻译中…
A string is called a beautiful string if and only if it satisfies the following conditions:
翻译中…
- Every character is
A,B, orC. - No two adjacent characters are the same.
翻译中…
For example, AB and BCAC are beautiful strings, while BB and CBAAC are not.
翻译中…
翻译中…
You are given a beautiful string $S$. On this string, you can repeatedly perform the following operation.
翻译中…
- Operation: Swap two adjacent characters in
$S$. Here,$S$must still be a beautiful string after the swap.
翻译中…
Find the lexicographically smallest string that $S$ can become.
翻译中…
$T$ test cases are given; solve each of them.
翻译中…
Constraints
翻译中…
$1\leq T\leq 10^5$$S$is a beautiful string.$1\leq |S|\leq 10^6$- The sum of
$|S|$over all test cases in a single input is at most$10^6$.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
T
\text{case}_1
\vdots
\text{case}_T
翻译中…
Each test case is given in the following format:
翻译中…
S
翻译中…
Output
翻译中…
Print $T$ lines. The $i$-th line should contain the lexicographically smallest string that $S$ can become for the $i$-th test case.
翻译中…
样例
Input #1
8
CAB
ACBCB
B
AC
BACBA
BABABA
ABCBCAC
CBABACABCBABABC
Output #1
ABC
ABCBC
B
AC
ABABC
BABABA
ABCACBC
ABABACBCACBCBAB
For each of the first and second test cases, here is a possible way to lexicographically minimize $S$:
- `CAB` → `ACB` → `ABC`
- `ACBCB` → `CABCB` → `CBACB` → `BCACB` → `BCABC` → `BACBC` → `ABCBC`
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。