#P16801. [蓝桥杯 2026 国 B] 货架换签
[蓝桥杯 2026 国 B] 货架换签
Problem Description
Xiao Lan manages a row of shelves, and there is a tag hanging in front of each shelf. Each tag contains the character or , forming a string of length from left to right.
Xiao Lan can perform any number of tag-swapping operations, or perform none. One tag-swapping operation is done as follows:
- Choose two non-overlapping consecutive segments in the current tag sequence.
- The two consecutive segments must contain the same number of tags (i.e., have the same length).
- The numbers of tags with in the two segments must be the same.
- Swap the contents of the two segments in place. The other tags remain unchanged, and the relative order inside each segment remains unchanged.
For example, in the string , you can choose the segment and the segment . Both have length , and both contain one character , so they can be swapped.
For two strings of the same length, compare them by the usual lexicographic order, and assume that is smaller than .
Now, please find the lexicographically smallest string that Xiao Lan can obtain after any number of valid tag-swapping operations.
Input Format
The first line contains an integer , representing the length of the string.
The second line contains a string of length , consisting only of characters and .
Output Format
Output one line containing a string of length , representing the lexicographically smallest string that can be obtained.
6
101001
011010
5
00000
00000
8
11110000
11110000
Hint
Sample Explanation 1
You can choose the segment formed by the st to nd characters of the original string, which is , and the segment formed by the th to th characters, which is . These two segments have the same length and both contain one character . After swapping them, you get .
It can be proven that among all reachable strings, is lexicographically the smallest.
Sample Explanation 2
There is no character in the string, so any valid operation will not change the string.
Sample Explanation 3
In the original string, to the left of each character there are characters . Under the constraints that valid operations must satisfy, it is impossible to obtain a lexicographically smaller string.
Constraints and Notes
For of the testdata, .
For of the testdata, .
For all testdata, , and consists only of characters and .
Translated by ChatGPT 5