sb题WA了三遍卧槽。。。。
set忘记clear了。。
被各路SA&SAM虐成狗TAT,不会SAM路过。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#define ll unsigned long long
#define base 233
#define inf 1000000007
using namespace std;
int n,cnt,L,R=inf,ans;
char s[6][2005];
ll hash[6][2005];
ll T[2005];
inline ll gethash(int i,int l,int r)
{
return hash[i][r]-hash[i][l-1]*T[r-l+1];
}
set<ll> mp1,mp2;
inline bool judge(int mid)
{
mp1.clear(); mp2.clear();
int l=strlen(s[1]+1);
for (int i=1;i<=l-mid+1;i++) mp1.insert(gethash(1,i,i+mid-1));
for (int i=2;i<=n;i++)
{
int l=strlen(s[i]+1);
for (int j=1;j<=l-mid+1;j++)
{
ll t=gethash(i,j,j+mid-1);
if (mp1.find(t)!=mp1.end()) mp2.insert(t);
}
mp1=mp2; mp2.clear();
}
return mp1.size();
}
int main()
{
scanf("%d",&n);
T[0]=1;
for (int i=1;i<=2000;i++) T[i]=T[i-1]*base;
for (int i=1;i<=n;i++)
{
scanf("%s",s[i]+1);
int l=strlen(s[i]+1);
R=min(R,l);
for (int j=1;j<=l;j++)
hash[i][j]=hash[i][j-1]*base+s[i][j]-'a';
}
L=0;
while (L<=R)
{
int mid=L+R>>1;
if (judge(mid)) ans=mid,L=mid+1; else R=mid-1;
}
cout << ans;
return 0;
}