P7734 [JDWOI-2] 01 String
Background
K and M wrote a 01 string.
Description
K and M wrote a 01 string $S$. The **end** of the string contains 2 consecutive spaces (denoted by `.`).
M defines a 01 string to be beautiful if and only if there are no inversions in the string, i.e., there is no `1` appearing before a `0`.
To satisfy M's requirement above, K decides to make some modifications to this 01 string. In each modification, K may choose two consecutive non-space characters in the string, move them to the positions of the spaces, and keep their relative order unchanged. Then, the original positions of the moved characters become spaces, and the original spaces are filled by these two characters.
To make the string beautiful as soon as possible, K hopes to finish within $10000$ steps. Now, find how many steps are needed to make the 01 string beautiful, and output a valid sequence of operations. If it is impossible to make the string beautiful, or if the number of steps must exceed $10000$, output `-1`.
**Note: You do not need to minimize the number of steps, and the final positions of the spaces can be anywhere.**
Input Format
One line containing a 01 string. The input is guaranteed to satisfy the statement.
Output Format
The first line contains an integer $m$, indicating the number of modifications.
The next $m$ lines each contain two integers $x, y$, meaning moving the two characters at positions $(x, x + 1)$ to positions $(y, y + 1)$.
Explanation/Hint
**This problem uses Special Judge and subtask-based evaluation.**
[Sample Explanation 1]
$\texttt{1100..} \rightarrow \texttt{..0011}$
[Sample Explanation 2]
It can be seen that no matter how you move, it is impossible to obtain a 01 string that satisfies M's requirement.
[Constraints and Subtask Scores]
Subtask 1 (20 pts): $3 \leq |S| \leq 10$.
Subtask 2 (30 pts): $3 \leq |S| \leq 100$.
Subtask 3 (50 pts): $3 \leq |S| \leq 2000$.
Translated by ChatGPT 5