Topic links
\ (description\)
The longest common substring of two strings is asked
\ (solution\)
Any substring must be prefixed with a suffix
You can put two strings together, separated by a character that never appeared, so that the maximum value of ht[] is the answer?
Not necessarily, the largest ht[] may be obtained by the same string, which is the same string
//3772k 516MS#include <cstdio>#include <cstring>#include <algorithm>Const intn=2e5+10;intN,l,sa[n],rk[n],ht[n],sa2[n],tm[n];CharS[n];voidGet_sa () {int*x=rk,*y=sa2,m= -; for(intI=1; i<=n; ++i) ++tm[x[i]=s[i]-' A '+1]; for(intI=1; i<=m; ++i) Tm[i]+=tm[i-1]; for(intI=n; I I.) sa[tm[x[i]]--]=i; for(intp=0, k=1; k<n; m=p,p=0, k<<=1) { for(intI=n-k+1; i<=n; ++i) y[++p]=i; for(intI=1; i<=n; ++i)if(sa[i]>k) Y[++p]=sa[i]-k; for(intI=0; i<=m; ++i) tm[i]=0; for(intI=1; i<=n; ++i) ++tm[x[i]; for(intI=1; i<=m; ++i) Tm[i]+=tm[i-1]; for(intI=n; I I.) sa[tm[x[y[i]]]--]=y[i]; Std::swap (x, y), p=x[sa[1]]=1; for(intI=2; i<=n; ++i) X[sa[i]]=y[sa[i-1]]==y[sa[i]]&&y[sa[i-1]+k]==y[sa[i]+k]?p:++p;if(p>=n) Break; } for(intI=1; i<=n; ++i) rk[sa[i]]=i; ht[1]=0; for(intk=0, p,i=1; i<=n; ++i) {if(rk[i]==1)Continue;if(k)--k; P=sa[rk[i]-1]; while(I+k<=n&&p+k<=n&&s[i+k]==s[p+k]) ++k; Ht[rk[i]]=k; }}intMain () {scanf ("%s", S+1), L=strlen (s+1); S[l+1]=' Z '+1; scanf"%s", S+2+L), N=strlen (s+1); Get_sa ();intres=0; for(intI=2; i<=n; ++i)if((sa[i]<=l) ^ (sa[i-1]<=l)) Res=std::max (Res,ht[i]); printf"%d", res);return 0;}
Poj.2774.long Long Message (suffix array multiplication)