#P9458. [入门赛 #14] 扶苏和串 (Hard Version)
[入门赛 #14] 扶苏和串 (Hard Version)
Background
As everyone knows, the string problems in the monthly Beginner Contest are all ideas enumerated by Fusu.
Problem Description
Given a 01 string , you may choose any non-empty substring of and reverse this substring once within .
What is the lexicographically smallest string you can obtain?
Formally, you can choose an interval satisfying , and construct a string such that:
$$t_i = \begin{cases}s_i, &i < l \text{ or } i > r \\ s_{r - (i - l)}, & l \leq i \leq r\end{cases}$$Minimize the lexicographic order of string .
Input Format
The input contains only one line with a string, representing .
Output Format
Output one line with a string, representing the lexicographically smallest string that can be obtained.
101
011
0010100
0000101
Hint
Explanation for Sample 1
. Reverse the underlined substring to get .
Explanation for Sample 2
. Reverse the underlined substring to get .
Constraints
Let denote the length of the input string.
- For of the testdata, . contains only characters .
Translated by ChatGPT 5