8983: link with Centrally Symmetric Strings

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:Special Judge 上传者:
提交:0 通过:0

题目描述


Given a string, determine if it can be represented as the concatenation of several centrally symmetric substrings.

Formally, a string SSS is centrally symmetric if and only if it satisfies one of the following conditions:
  •  SSS is an empty string.
  •  S=o∣s∣x∣zS = o|s|x|zS=osxz, i.e., SSS is one of the four letters: o, s, x and z.
  •  S=bSq∣dSp∣pSd∣qSb∣nSu∣uSn∣oSo∣sSs∣xSx∣zSzS = bSq|dSp|pSd|qSb|nSu|uSn|oSo|sSs|xSx|zSzS=bSqdSppSdqSbnSuuSnoSosSsxSxzSz, i.e., SSS starts and ends with a pair of centrally symmetric letters, and the middle part is also a centrally symmetric substring.

A string SSS is considered good if and only if there exists an integer n≥1n \geq 1n1 such that S=T1T2⋯TnS = T_1T_2 \cdots T_nS=T1T2Tn, where TiT_iTi (1≤i≤n1 \le i \le n1in) is a centrally symmetric substring.

Given a string SSS, determine whether it is a good string.

输入格式


The input contains multiple test cases.
The first line contains an integer T(1≤T≤106)T (1 \leq T \leq 10^6)T(1T106), indicating the number of test cases.
The following TTT lines each contain a string SSS (1≤∣S∣≤1061 \leq |S| \leq 10^61S106) consisting of lowercase English letters, representing the string to be tested.
It is guaranteed that ∑∣S∣≤5×106\sum |S| \leq 5 \times 10^6S5×106, where ∣S∣|S|S represents the length of string SSS.

输出格式


For each test case, if the string is good, output “Yes”; otherwise, output “No”.

You can output each letter in any case (lowercase or uppercase). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be accepted as a positive answer.

输入样例 复制

3
sosos
hahaha
sbzzq

输出样例 复制

Yes
No
Yes

数据范围与提示


For the third test case, the string can be divided into two substrings, “s” and “bzzq”, both of which are centrally symmetric substrings. Therefore, the output is “Yes”.

分类标签