#P8368. [LNOI2022] 串
[LNOI2022] 串
Problem Description
To help you better understand the statement, here are some definitions about strings:
- For a string , its length is defined as .
- For two strings and , we call a substring of if (i.e., is the empty string) or such that . If or in the above condition can be , then is called a prefix of ; if or in the above condition can be , then is called a suffix of .
Given a string consisting of lowercase English letters, you need to find a string sequence that is as long as possible, satisfying:
- is a substring of .
- , .
- , there exists a substring of with length , such that the prefix of with length is , and the suffix of with length is .
Output the maximum possible length of such a sequence (i.e., the maximum value of ).
Input Format
This problem has multiple test cases. The first line contains an integer , denoting the number of test cases. For each test case, one line contains a string consisting of lowercase English letters.
Output Format
For each test case, output one integer per line, representing the maximum length of the string sequence described in the statement.
3
abcd
abab
a
2
3
0
Hint
[Sample Explanation #1]
In the following, the symbol denotes the empty string.
For the first test case, we can find the following string sequence: $T_0 = \epsilon, T_1 = \texttt{b}, T_2 = \texttt{cd}$, where .
For the second test case, we can find the following string sequence: $T_0 = \epsilon, T_1 = \texttt{b}, T_2 = \texttt{ab}, T_3 = \texttt{bab}$, where $S'_1 = \texttt{ab}, S'_2 = \texttt{bab}, S'_3 = \texttt{abab}$.
For the third test case, we can find the following string sequence: .
[Sample #2]
See the attachments string/string2.in and string/string2.ans.
The string lengths in this sample have some gradients. You can use this sample to check your program.
[Sample #3]
See the attachments string/string3.in and string/string3.ans.
This sample satisfies Special Property A.
[Constraints]
Let denote the sum of string lengths of all test cases in a test.
For of the testdata, , , .
| Test Point ID | Special Property | ||
|---|---|---|---|
| None | |||
| A | |||
| None | |||
Special Property A: each character in the string is generated independently and uniformly at random among lowercase letters.
[Notes]
The input and output size of this problem is large, so please use faster I/O.
For example, if your code uses cin and cout for I/O, you may add the following statements after the I/O redirection statements (freopen, fopen, etc.) to speed up I/O.
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
After adding these statements, it is not recommended to use cin, cout together with other I/O methods.
Translated by ChatGPT 5