Theme Section
1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 using namespace std; 5 typedef long long ll; 6 inline ll read(){ 7 int x=0,f=1;char ch=getchar(); 8 while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();} 9 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 10 return x*f; 11 } 12 13 /***********************************************************/ 14 15 const int maxn = 1e6+7; 16 char s[maxn]; 17 int Next[maxn]; 18 19 int main(){ 20 int t; 21 t = read(); 22 while(t--){ 23 scanf("%s", s); 24 int len = strlen(s); 25 Next[0] = -1; 26 int k = -1; 27 for(int i = 0;i <= len;){ 28 if(k == -1 || s[i] == s[k]){ 29 Next[++i] = ++k; 30 } 31 else k = Next[k]; 32 } 33 int ans = 0; 34 for(int i = Next[len];i >= 1;i--){ 35 if(ans) break; 36 for(int j = len - i;j >= i;j--){ 37 if(Next[j] >= i){ 38 ans = i; 39 break; 40 } 41 } 42 } 43 printf("%d\n", ans); 44 } 45 return 0; 46 }