atcoder#ARC113E. [ARC113E] Rvom and Rsrev
[ARC113E] Rvom and Rsrev
Score : points
Problem Statement
Given is a string consisting of a
and b
. Find the lexicographically greatest string that can be obtained by applying the following operation to zero or more times:
- Choose two characters of that are the same letter. Reverse the string between them and delete the chosen two characters. In other words: let denote the -th character of . Choose such that and replace with $s_1\dots s_{i-1}s_{j-1}\dots s_{i+1}s_{j+1}\dots s_{|S|}$.
In this problem, you are given test cases. The -th test case is represented as and asks you to solve the problem above for .
Constraints
- consists of
a
andb
.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the lexicographically greatest string that can be obtained by applying the operation to zero or more times.
20
abbaa
babbb
aabbabaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbabaaaaabbaababaaabbabbbbbaaaaa
babbbaaaabaababbbabaabaaaaababaa
bbaababababbbaaabaabababaabbabab
abaabbabaabaaaaabaaaabbaabaaaaab
aabababbabbabbabbaaaabbabbbabaab
aabababbabbbbaaaabbaaaaabbaaaabb
abbbbaabaaabababaaaababababbaabb
aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbb
aaaaaaaaaabbbbbbbbbbbbbbbbbbbbbb
abababaaababaaabbbbbaaaaaaabbbbb
aabbaaaaababaabbbbbbbbbaabaaabbb
babababbababbbababbbbbababbbabbb
bbbbababbababbbabababbabbabbbbbb
aaaaaaaaaaaaaaaaababababbbabbbbb
aabababbabbabababababababbbbabbb
bba
bba
bbba
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbaaaaaaaa
bbbbbbbbbbbbbaaaaaaa
bbbbbbbbbbbbbbbb
bbbbbbbbbb
bbbbbbbbbbbbbbbbab
bbbbbbbbbbbbbb
bbbbbbbbbbbbbabb
abbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbaaaaaaaaa
bbbbbbbbbbbbbbbaaaaa
bbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbba
bbbbbbbbbaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbba
- In the -st test case, we can do the operation for the -st and -th characters to make
bba
. - In the -nd test case, we can do the operation for the -st and -th characters to make
bba
. - In the -rd test case, we can do the operation for the -st and -nd characters to make
bbabaa
, then do it for the -rd and -th characters to makebbba
.