#P5446. [THUPC 2018] 绿绿和串串
[THUPC 2018] 绿绿和串串
Description
Lvlvl has a non-empty string consisting of lowercase letters, but Yazid does not know what it is.
We define the flip operation: flip-copy a string using its last character as the axis of symmetry. Formally, if the string to be flipped is , then take the first characters, reverse them, and append them to the end of the string.
For example, after applying the flip operation to abcd, we get abcdcba; if we apply the flip operation times in a row to qw, we get qwqwq; for z, no matter how many times we apply the flip operation, it will not change.
The playful Lvlvl performed the flip operation several times (possibly times).
Then the naughty Lvlvl showed a non-empty string , and said that is a prefix of the final string . Now he wants to test Yazid: what lengths could the initial string have?
Yazid asked you, who are participating in the Tsinghua campus contest, to help solve this problem. But the clever Yazid noticed that every integer greater than must be a possible length of , so you only need to tell him the possible lengths of that do not exceed .
To help you understand the problem, Yazid also explains some concepts and notation:
- For a string , denotes its length.
- For a string , we say that a string is its prefix if and only if , and for every integer with , the -th character of from the left is the same as the -th character of from the left. (Intuitively, appears at the beginning of .)
- For example:
abcis a prefix ofabcdefg;abais not a prefix ofabba;zis a prefix ofz; the empty string is a prefix of any string.
- For example:
Input Format
The input contains multiple test cases. The first line contains an integer indicating the number of test cases. Each test case is described as follows:
- One line contains a non-empty string consisting only of lowercase letters.
Output Format
For each test case, output one line:
- Output all possible values of that do not exceed , in increasing order, separated by a single space.
4
abcdcb
qwqwq
qaqaqqq
carnation
4 6
2 3 4 5
6 7
9
Hint
Constraints
It is guaranteed that and .
denotes the total length of all test cases in a single test point.
Notes
- The input size is large, so please pay attention to input efficiency.
- What does the last string in the sample mean?
Copyright Information
From the 2018 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2018). Thanks to Pony.ai for supporting this contest.
Resources such as the editorial can be found at https://github.com/wangyurzee7/THUPC2018.
Translated by ChatGPT 5
京公网安备 11011102002149号