luogu#P7919. [Kubic] ABC
[Kubic] ABC
Background
It is recommended to read the background of Problem D first.
Problem Description
You are given a string of length that contains only . You may perform several operations. In each operation:
-
First choose an interval , and you must ensure that .
-
Then choose three characters , and change all in into , all into , and all into . may be equal.
Find the minimum number of operations needed to make any two adjacent characters in different, and output a construction.
Input Format
The first line contains an integer .
The second line contains a string of length .
Output Format
The first line contains an integer , the number of operations in your constructed plan.
The next lines each contain two integers and three characters .
You must ensure that .
Note: There is no need to, and you should not, add spaces between (see the sample output).
5
ABBAA
1
3 4 BAC
5
ABCBA
0
Hint
For of the testdata, .
Constraints
| Score | Special Property | ||
|---|---|---|---|
| No special limits | |||
| None | |||
| No special limits | |||
| None | |||
| No special limits |
Scoring
You will get points on this test point if any of the following happens:
-
The output format does not meet the requirements.
-
You output extra information (including spaces and newline characters).
-
The number of operations in your constructed plan is different from the official answer.
-
Your constructed plan does not satisfy the problem requirements.
-
Time limit exceeded.
If none of the above happens, you will get full points on this test point.
It is guaranteed that the SPJ uses no more than .
Sample Explanation 1
One possible sequence of operations is:
ABBAA
ABABA
It can be proven that there is no better plan.
Sample Explanation 2
The initial sequence already satisfies the requirements, so you can directly output a single line .
Translated by ChatGPT 5