Longest common substring ... Two strings are joined together, separated by a special character in the middle. After you find the height, enumerate the height and see if two suffixes are distributed in the two-segment string: If so, this value can be used as an answer. The maximum value can be taken.
1 Constmaxn=200419;2 var3C,h,rank,sa,x,y:Array[0.. MAXN] ofLongint;4 N,k:longint;5 s:ansistring;6 7 functionMax (x,y:longint): Longint;begin ifX>y ThenExit (x)ElseExit (y);End;8 functionMin (x,y:longint): Longint;begin ifX<y ThenExit (x)ElseExit (y);End;9 procedureSwapvarX,y:longint);varTmp:longint;begintmp:=x;x:=y;y:=tmp;End;Ten One procedureMake ; A varP,i,tot:longint; - begin -p:=1; the whileP<n Do - begin -Fillchar (C,sizeof (c),0); - fori:=1 toN-p Doy[i]:=rank[i+p]; + fori:= n-p+1 toN Doy[i]:=0; - fori:=1 toN DoInc (C[y[i]); + fori:=1 toN DoInc (c[i],c[i-1]); A fori:=1 toN Do at begin -sa[c[y[i]]]:=i; - Dec (c[y[i]]); - End; -Fillchar (C,sizeof (c),0); - fori:=1 toN Dox[i]:=Rank[i]; in fori:=1 toN DoInc (C[x[i]); - fori:=1 toN DoInc (c[i],c[i-1]); to fori:= NDownto 1 Do + begin -y[sa[i]]:=C[x[sa[i]]; the Dec (c[x[sa[i]]); * End; $ fori:=1 toN Dosa[y[i]]:=i;Panax Notoginsengtot:=1; -rank[sa[1]]:=1; the fori:=2 toN Do + begin A if(x[sa[i]]<>x[sa[i-1]])or(x[sa[i]+p]<>x[sa[i-1]+P]) ThenInc (TOT); therank[sa[i]]:=tot; + End; -p:=p<<1; $ End; $ fori:=1 toN Dosa[rank[i]]:=i; - End; - the procedureMakeh; - varI,j,p:longint;Wuyi begin theh[1]:=0; p:=0; - fori:=1 toN Do Wu begin -P:=max (P-1,0); About ifrank[i]=1 Thencontinue; $j:=sa[rank[i]-1]; - while(i+p<=n) and(j+p<=n) and(S[i+p]=s[j+p]) DoInc (P); -h[rank[i]]:=p; - End; A End; + the procedureInit; - varI,tot:longint; $ s1:ansistring; the begin the Readln (s); thes:=s+'#'; thek:=length (s); - readln (S1); ins:=s+S1; theFillchar (C,sizeof (c),0); then:=length (s); About fori:=1 toN Dox[i]:=Ord (s[i]); the fori:=1 toN DoInc (C[x[i]); the fori:=1 to - DoInc (c[i],c[i-1]); the fori:=1 toN Do + begin -sa[c[x[i]]]:=i; the Dec (c[x[i]]);Bayi End; therank[sa[1]]:=1; thetot:=1; - fori:=2 toN Do - begin the ifx[sa[i]]<>x[sa[i-1]] ThenInc (TOT); therank[sa[i]]:=tot; the End; the Make ; - Makeh; the End; the the functionRange (X,y:longint): boolean;94 begin the if(x<k) and(y>k) Thenexit (true); the if(x>k) and(y<k) Thenexit (true); the exit (false);98 End; About - proceduresolve;101 varAns,i:longint;102 begin103ans:=0;104 fori:=2 toN Do ifRange (sa[i],sa[i-1]) Thenans:=Max (H[i],ans); the writeln (ans);106 End;107 108 Begin109 Init; the solve;111End.
"POJ2774" Long Long Message (SA)