#4614. [UOI 2025] Reversal ABC
[UOI 2025] Reversal ABC
[UOI 2025] Reversal ABC
题目描述
Given a string $s$ consisting of characters $\texttt{A}$, $\texttt{B}$, and $\texttt{C}$.In one operation, you are allowed to choose two adjacent elements of the string that are in the following order: , , or , and swap them.
Find the maximum number of consecutive operations that can be performed on the string .
In this problem, each test contains several sets of input data. You need to solve the problem independently for each such set.
输入格式
The first line contains one integer $T$ $(1\le T\le 10^5)$ --- the number of sets of input data. The description of the input data sets follows.In the first line of each input data set, there is one integer --- the length of the string .
In the second line of each input data set, there is a string of length , consisting of characters , , and .
It is guaranteed that the sum of across all input data sets of a single test does not exceed .
输出格式
For each set of input data, output on a separate line one integer --- the maximum number of consecutive operations that can be performed on the string $s$.2
5
ABCCA
19
CCAABBBABBAAABBCCAA
3
28
提示
In the first set of input data from the first example, no more than $3$ consecutive operations can be performed on the string $\texttt{ABCCA}$. One example of how $3$ consecutive operations can be performed is $[\texttt{ABCCA} \rightarrow \texttt{BACCA}, \texttt{BACCA} \rightarrow \texttt{BACAC}, \texttt{BACAC} \rightarrow \texttt{BAACC}]$.Scoring
Let be the sum of over all input data sets of one test.
- ( points): the answer is equal to or ;
- ( points): ;
- ( points): for ;
- ( points): has the form $\texttt{AA}\ldots \texttt{AABB}\ldots \texttt{BBCC}\ldots \texttt{CC}$ (that is, $x \cdot \texttt{A} + y \cdot \texttt{B} + z \cdot \texttt{C}$ for certain positive , , );
- ( points): for ;
- ( points): , ;
- ( points): ;
- ( points): ;
- ( points): without additional constraints. 标签: P12550|2025|UOI(乌克兰)