#d2552. 循环子串
循环子串
Cyclic Substring
Problem Description
A string is a cyclic substring of another string if and only if there exists some such that, after cyclically shifting right by positions to obtain a new string , is a substring of .
For example: abc is a cyclic substring of cefab (cefab shifted right by positions becomes abcef, and abc is a substring of abcef).
A string is a fully cyclic string if and only if for any substring of it, is a cyclic substring of ( is the reversal of , e.g. abc reversed is cba).
Given a string of length , determine whether it is a fully cyclic string.
Input Format
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 next line contains a string of length , consisting only of lowercase letters.
Output Format
For each test case, if the string is a fully cyclic string, output YES; otherwise output NO. Output a newline between consecutive test cases.
Sample Input
2
4
ccca
11
eeaafbddfaa
Sample Output
YES
NO
Constraints
For all data, , , and .
Hint
- This problem can be solved with only basic syntax knowledge.
- What does "any substring" mean?
- If a substring contains another substring, can we just figure out the validity of the larger substring and infer the validity of the smaller one?
- Think from larger substrings down to smaller ones: what is the largest substring?