#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 11 swap. Sorting the string qiao needs a total of 44 swaps.

Xiao Lan’s lucky number is VV. 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 VV 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 VV, Xiao Lan’s lucky number.

Output Format

Output one line containing the required string.

4
bbaa
100
jihgfeeddccbbaa

Hint

For 30%30\% of the testdata, 1V201 \leq V \leq 20.

For 50%50\% of the testdata, 1V1001 \leq V \leq 100.

For all testdata, 1V1000001 \leq V \leq 100000.

Lanqiao Cup 2020, Second Round of the Provincial Contest, Group A, Problem J (Group B, Problem J).

Translated by ChatGPT 5