#P10331. [UESTCPC 2024] 消消乐
[UESTCPC 2024] 消消乐
Problem Description
bjh has a string of length that consists only of the characters 0 and 1.
In each operation, bjh can choose a maximal substring of length greater than that contains only one kind of character, and change the whole substring into the opposite character (for example, after one operation, can become or ).
bjh will keep operating until the string can no longer be operated on. Please find, among all possible operation sequences, the difference between the maximum number of operations and the minimum number of operations.
Input Format
This problem contains multiple test cases. The first line contains an integer , the number of test cases.
For each test case, the first line contains an integer , the length of the string.
The second line contains a string , the initial string.
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, output an integer, the difference between the maximum number of operations and the minimum number of operations.
2
5
11001
5
11000
1
0
Hint
Translated by ChatGPT 5