#P6303. [eJOI 2018] AB 串
[eJOI 2018] AB 串
Description
You have two strings , and they contain only the letters a and b. You may perform the following operation multiple times: choose a prefix of and a prefix of , and swap them. (Note that the prefix can be empty or the entire string.)
Your task is to find a sequence of operations such that after performing them, one string contains only the character a, and the other contains only the character b.
You should use as few operations as possible, but a non-optimal solution may still get partial points. For details, see the “Constraints and Hint” section.
Input Format
The input consists of two lines, containing the two strings .
Output Format
Output an integer () on the first line, representing the total number of operations.
In the next lines, each line contains two integers , which are the prefix lengths of and to be swapped in this operation, respectively.
If there are multiple valid solutions, you may output any of them.
bab
bb
2
1 0
1 3
bbbb
aaa
0
Hint
Explanation for Sample :
In this sample, first swap the prefix of length of the first string with the prefix of length of the second string, i.e. insert b at the beginning of the second string. The two strings become ab and bbb. Next, swap the prefix of length of the first string with the prefix of length of the second string, i.e. swap a and bbb. The two strings become bbbb and a, achieving the goal.
Explanation for Sample :
It is already in the required final state.
Scoring Policy
Let be the number of operations you output, and be the number in the official answer. This problem uses SPJ.
-
If for all test cases , you will get of the score.
-
If for all test cases , you will get of the score. (Rounded to the nearest integer.)
-
If for all test cases , you will get of the score. (Rounded to the nearest integer.)
-
If for all test cases , you will get of the score. (Rounded to the nearest integer.)
-
If for at least one test case , you will get of the score.
For of the testdata, it is guaranteed that $1\leq \lvert s\rvert,\lvert t\rvert \leq 2\times 10^5$, where denote the lengths of , respectively. It is also guaranteed that at least one string contains at least one character a, and at least one string contains at least one character b.
Constraints
| Subtask ID | Score | Constraints |
|---|---|---|
, and there is exactly one character a in total in the two strings. |
||
| . | ||
| . | ||
| . | ||
| $1\leq \lvert s\rvert,\lvert t\rvert \leq 2\times 10^3$. | ||
| No additional constraints. |
Translated by ChatGPT 5
京公网安备 11011102002149号