#P10841. 【MX-J2-T2】Turtle and Strings
【MX-J2-T2】Turtle and Strings
Background
Original problem link: https://oier.team/problems/J2C.
Problem Description
You are given a string consisting only of lowercase letters.
A sequence of strings is valid if and only if:
- , where means string concatenation.
- .
Find the maximum possible length of a valid string sequence.
Input Format
This problem has multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case:
The first line contains a positive integer , the length of the string.
The second line contains a string of length consisting only of lowercase letters.
Output Format
For each test case, output one line containing an integer, representing the maximum length of a valid string sequence.
4
3
abc
5
aabbb
6
aaaaaa
10
pppqqppppq
3
3
4
7
Hint
Sample Explanation
In the first test case, a valid sequence with maximum length is .
In the second test case, a valid sequence with maximum length is .
In the third test case, a valid sequence with maximum length is .
Constraints
This problem uses bundled testdata and enables subtask dependencies.
| Subtask ID | Score | Special Property | Subtask Dependencies | ||
|---|---|---|---|---|---|
| None | None | ||||
| None | |||||
| There exists exactly one position such that | |||||
| None | |||||
For all testdata, , , and consists only of lowercase letters.
Translated by ChatGPT 5