http://www.spoj.com/problems/PHRASES/
基本应用——每个字符串至少出现两次且不重复的最长子串
memset的mmin[]和mmax开大了简直是作死,狂T不止。。。
//#define _TEST _TEST
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
/************************************************
Code By willinglive Blog:http://willinglive.cf
************************************************/
#define rep(i,l,r) for(int i=(l),___t=(r);i<=___t;i++)
#define per(i,r,l) for(int i=(r),___t=(l);i>=___t;i--)
#define MS(arr,x) memset(arr,x,sizeof(arr))
#define LL long long
#define INE(i,u,e) for(int i=head[u];~i;i=e[i].next)
inline const int read()
{int r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;
for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}
/
int n;
char s[100010];
int t1[100010],t2[100010],c[100010];
int sa[100010],height[100010],rk[100010];
int sz;
int mmax[11],mmin[11],bel[100010];
/
inline void MAX(int &a,int b){if(b>a)a=b;}
inline void MIN(int &a,int b){if(b<a)a=b;}
void get_sa(int *x,int *y,int *sa,int n,int m)
{
rep(i,0,m-1) c[i]=0;
rep(i,0,n-1) c[x[y[i]]]++;
rep(i,1,m-1) c[i]+=c[i-1];
per(i,n-1,0) sa[--c[x[y[i]]]]=y[i];
}
void get_height(char *s,int *sa,int *height,int n)
{
int i,j,k=0;
rep(i,1,n) rk[sa[i]]=i;
for(i=0;i<n;height[rk[i++]]=k)
for(k?k--:0,j=sa[rk[i]-1];s[i+k]==s[j+k];k++);
}
void da(char *s,int *sa,int *height,int n)
{
int i,j,p,*x=t1,*y=t2,*t,m=128;
rep(i,0,n-1) x[i]=s[i],y[i]=i;
get_sa(x,y,sa,n,m);
for(j=p=1;p<n;j<<=1,m=p)
{
p=0;
rep(i,n-j,n-1) y[p++]=i;
rep(i,0,n-1) if(sa[i]>=j) y[p++]=sa[i]-j;
get_sa(x,y,sa,n,m);
t=x;x=y;y=t;p=1;x[sa[0]]=0;
rep(i,1,n-1) x[sa[i]]=y[sa[i]]==y[sa[i-1]]&&y[sa[i]+j]==y[sa[i-1]+j]?p-1:p++;
}
get_height(s,sa,height,n);
}
inline bool cal(int md)
{
bool flag=1;
rep(i,1,n)
{
if(mmax[i]-mmin[i]<md){flag=0;break;}
}
return flag==1;
}
bool check(int md)
{
MS(mmin,0x3f); MS(mmax,0);
rep(i,2,sz)
{
if(height[i]>=md)
{
MAX(mmax[bel[sa[i]]],sa[i]);
MIN(mmin[bel[sa[i]]],sa[i]);
MAX(mmax[bel[sa[i-1]]],sa[i-1]);
MIN(mmin[bel[sa[i-1]]],sa[i-1]);
}
else
{
if(cal(md)) return 1;
MS(mmin,0x3f); MS(mmax,0);
}
}
return cal(md);
}
/
void input()
{
MS(t1,0); MS(t2,0); MS(c,0); MS(sa,0); MS(height,0); MS(rk,0);
sz=1;
rep(i,1,n=read())
{
scanf("%s",s+sz);
int old=sz;
sz+=strlen(s+sz);
rep(j,old,sz-1) bel[j]=i;
s[sz++]=i;
}
sz-=2;
}
void solve()
{
da(s,sa,height,sz+1);
int l=0,r=sz/n+1,mid;
while(l<r)
{
mid=l+r+1>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
printf("%d\n",l);
}
/
int main()
{
#ifndef _TEST
freopen("std.in","r",stdin); freopen("std.out","w",stdout);
#endif
rep(i,1,read())
input(),solve();
return 0;
}