Main topic:
It's a substring of M-strings, all of which have appeared. Substrings can also appear in the reverse string of the string.
Thinking Analysis:
Actually WA is on all 5 "a" data.
The nether cannot be 0 for two points.
The idea is that the original string and the reverse string are all processed out, put into STR, and then in each string in the middle of adding a never appeared.
Note that typing is more than just letters here.
Then run through the suffix array.
Then count it with the tag.
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <
Cmath> #define MAXN 100005 using namespace std;
int STR[MAXN];
int sa[maxn],t1[maxn],t2[maxn],c[maxn],n;
void suffix (int m) {int *x=t1,*y=t2;
for (int i=0; i<m; i++) c[i]=0;
for (int i=0; i<n; i++) c[x[i]=str[i]]++;
for (int i=1; i<m; i++) c[i]+=c[i-1];
for (int i=n-1; i>=0; i--) sa[--c[x[i]]]=i;
for (int k=1; k<=n; k<<=1) {int p=0;
for (int i=n-k; i<n; i++) y[p++]=i;
for (int i=0; i<n; i++) if (sa[i]>=k) y[p++]=sa[i]-k;
for (int i=0; i<m; i++) c[i]=0;
for (int i=0; i<n; i++) c[x[y[i]]]++;
for (int i=0; i<m; i++) c[i]+=c[i-1];
for (int i=n-1; i>=0; i--) sa[--c[x[y[i]]]]=y[i];
Swap (x, y);
P=1;
x[sa[0]]=0;
for (int i=1; i<n; i++) x[sa[i]]=y[sa[i-1]]==y[sa[i]]&&y[sa[i-1]+k]==y[sa[i]+k]?p-1:p++; if (p>=n) BreAk
M=p;
}} int RANK[MAXN],HEIGHT[MAXN];
void GetHeight () {int k=0;
for (int i=0; i<n; i++) rank[sa[i]]=i;
for (int i=0; i<n; i++) {if (k) k--;
if (!rank[i]) continue;
int j=sa[rank[i]-1];
while (Str[i+k]==str[j+k]) k++;
Height[rank[i]]=k;
}} char tmp[105];
BOOL vis[105];
int DEX[MAXN];
BOOL Check (int len,int m) {int cnt=m;
memset (vis,false,sizeof Vis);
for (int i=1;i<n;i++) {if (Height[i]<len) {if (!cnt) return true;
Cnt=m;
memset (vis,false,sizeof Vis);
} else {if (!vis[dex[sa[i-1]]) {cnt--;
Vis[dex[sa[i-1]]]=true;
} if (!vis[dex[sa[i]]) {cnt--;
Vis[dex[sa[i]]]=true;
}}} return false;
} int main () {int T;
scanf ("%d", &t);
while (t--) {n=0;
int m;
scanf ("%d", &m);
for (int i=1;i<=m;i++) {scanf ("%s", TMP);
int Len=strlen (TMP);
for (int j=0;j<len;j++) {dex[n]=i;
STR[N++]=TMP[J];
} dex[n]=i;
str[n++]=128+i*2-1;
Reverse (Tmp,tmp+len);
for (int j=0;j<len;j++) {dex[n]=i;
STR[N++]=TMP[J];
} dex[n]=i;
str[n++]=128+i*2;
} str[n-1]=0;
Suffix (400);
GetHeight ();
int l=1,r=100,ans=0;
while (l<=r) {int mid= (L+R) >>1;
if (check (mid,m)) ans=mid,l=mid+1;
else r=mid-1;
} printf ("%d\n", ans);
} return 0;
}