#P9574. 「TAOI-2」Break Through the Barrier
「TAOI-2」Break Through the Barrier
Problem Description
There is a string consisting of and .
You can perform the following operation: choose a substring of length that is exactly , and change it to . You may perform this operation any number of times (or not perform it at all).
Define the weight of a string as the length of the longest consecutive segment of . You need to make the weight of the string as large as possible using the operation above. Output this maximum value.
- Definition of substring: a string is called a substring of a string if and only if can be obtained by deleting some (possibly ) characters from the beginning of and some characters from the end of .
- Definition of a consecutive segment: a substring of the original string that consists only of .
Input Format
The first line contains a positive integer , indicating the number of test cases.
For each test case, the first line contains a positive integer , indicating the length of the string. The second line contains a string of length , which is the string in this problem.
Output Format
Output lines. Each line contains a non-negative integer, representing the length of the longest consecutive segment of .
6
3
TTT
4
BTTB
5
TBBTT
6
BTBTBB
7
BTTBTTB
17
TTBTBTTBTBTTTBTTB
3
2
2
1
3
5
Hint
This problem uses bundled testdata.
Let be the sum of over all test cases.
- Subtask 0 (5 pts): .
- Subtask 1 (20 pts): , .
- Subtask 2 (25 pts): .
- Subtask 3 (5 pts): it is guaranteed that the given string cannot perform any operation.
- Subtask 4 (45 pts): no special restrictions.
For all testdata, , , , and the string contains only the characters B and T.
Translated by ChatGPT 5