Test instructions: Is the maximum substring that asks you to ask for two strings
#include <bits/stdc++.h>Const intmaxn=200005;using namespacestd;intS[MAXN],T1[MAXN],T2[MAXN],X[MAXN],C[MAXN],SA[MAXN],RANK[MAXN],HEIGHT[MAXN];CharSTR[MAXN];///The sa is a suffix array, which records the position of the sorted suffix array///rank is the position of the suffix in the suffix array that the record begins with I///height is an array of heights, representing the common prefix of two suffixes adjacent to the sortvoidBuild_sa (int*s,intNintm) { inti,*x=t1,*y=t2,k; for(i=0; i<m; i++) c[i]=0; for(i=0; i<n; i++) c[x[i]=s[i]]++; for(i=1; i<m; i++) c[i]+=c[i-1]; for(i=n-1; i>=0; i--) sa[--c[x[i]]]=i; for(k=1; k<=n; k<<=1){ intp=0; for(i=n-k; i<n; i++) y[p++]=i; for(i=0; i<n; i++)if(sa[i]>=k) y[p++]=sa[i]-K; for(i=0; i<m; i++) c[i]=0; for(i=0; i<n; i++) c[x[y[i]]]++; for(i=1; i<m; i++) c[i]+=c[i-1]; for(i=n-1; i>=0; i--) sa[--c[x[y[i]]]]=Y[i]; Swap (x, y); P=1; x[sa[0]]=0; for(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; }}voidGetHeight (intN) { inti,j,k=0; for(i=0; i<n; i++) Rank[sa[i]]=i; for(i=0; i<n; i++){ if(k) k--; intj=sa[rank[i]-1]; while(S[i+k]==s[j+k]) k++; Height[rank[i]]=K; }}intMain () {intLen1,len,i,ans; while(~SCANF ("%s", str)) {Len=strlen (str); Len1=Len; Str[len]='$'; scanf ("%s", str+len+1); Len=strlen (str); for(i=0; i<len; i++) S[i]=Str[i]; Build_sa (S,len, the); GetHeight (len); Ans=0; for(i=0; i<len; i++){ if(height[i]>ans&& (sa[i-1]<LEN1&&SA[I]>=LEN1) | | (sa[i-1]>=len1&&sa[i]<LEN1))) Ans=Height[i]; } printf ("%d\n", ans); } return 0;}
Suffix array template hdu1403