#P8719. [蓝桥杯 2020 省 AB2] 字串排序
[蓝桥杯 2020 省 AB2] 字串排序
Problem Description
Xiao Lan has recently learned some sorting algorithms, and bubble sort impressed him a lot.
In bubble sort, each time you can only swap two adjacent elements.
Xiao Lan found that if you sort the characters in a string and only allow swapping two adjacent characters, then among all possible sorting methods, bubble sort uses the fewest total swaps.
For example, sorting the string lan only needs swap. Sorting the string qiao needs a total of swaps.
Xiao Lan’s lucky number is . He wants to find a string that contains only lowercase English letters, such that performing bubble sort on the characters of this string requires exactly swaps. Please help Xiao Lan find such a string. If there are multiple possible strings, output the shortest one. If there are still multiple shortest ones, output the lexicographically smallest one. Note that the string may contain repeated characters.
Input Format
The first line contains an integer , Xiao Lan’s lucky number.
Output Format
Output one line containing the required string.
4
bbaa
100
jihgfeeddccbbaa
Hint
For of the testdata, .
For of the testdata, .
For all testdata, .
Lanqiao Cup 2020, Second Round of the Provincial Contest, Group A, Problem J (Group B, Problem J).
Translated by ChatGPT 5