#P6709. [CCC 2020] Swapping Seats
[CCC 2020] Swapping Seats
Description
There are people sitting around a round table.
There are three groups, and each person belongs to one group.
Now you want people from the same group to sit together.
Each time, you may swap the seats of two people. Output the minimum number of swaps.
Input Format
A single line containing a string of length , representing the groups of all people in clockwise order.
If is A, then the -th person belongs to the first group, and so on.
Output Format
A single line containing one integer, the minimum number of swaps.
BABCBCACCA
2
Hint
Sample Explanation
$\texttt{BABCBCACCA}\to\texttt{AABCBCBCCA}\to\texttt{AABBBCCCCA}$.
Subtasks
This problem uses bundled testdata, and the Subtask scores have been slightly adjusted.
- Subtask 1 ( points):
ABand . - Subtask 2 ( points):
AB. - Subtask 3 ( points): .
- Subtask 4 ( points): No special constraints.
For of the testdata, it is guaranteed that ABC and .
Notes
This problem is translated from Canadian Computing Competition 2020 Senior T4 Swapping Seats.
Translated by ChatGPT 5
京公网安备 11011102002149号