"SPOJ220" relevant phrases of annihilation (SA)

Source: Internet
Author: User

Successfully completed 3 even t! Yes, three-way tle is simply not good enough, so roll to see if the template is a problem. Took 3 copies of the other P-party template and threw it up, eh continue tle ... Konjac Konjac said he was powerless ...

Thought like paper inside said, still two minutes length then group ... Then record the maximum and minimum values of each character to determine if the entire set is satisfied ... Done... It's actually quite simple to write ...

Constmaxn=100419;varH,sum,rank,x,y,sa,c,lx,rx,col:Array[0.. MAXN] oflongint; n,k,maxlen,t,q:longint; s:ansistring ;functionMax (x,y:longint): Longint;begin ifX>y ThenExit (x)ElseExit (y);End;functionMin (x,y:longint): Longint;begin ifX<y ThenExit (x)ElseExit (y);End;procedureSwapvarX,y:longint);varTmp:longint;begintmp:=x;x:=y;y:=tmp;End;procedureMake ;varP,i,j,tot:longint;begin  whileP<n Do  beginFillchar (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]);  fori:=1  toN Do    beginSa[c[y[i]]:=i;    Dec (C[y[i]]); End; Fillchar (C,sizeof (c),0);  fori:=1  toN Dox[i]:=Rank[i];  fori:=1  toN DoInc (C[x[i]);  fori:=1  toN DoInc (c[i],c[i-1]);  fori:= NDownto 1  Do    beginY[sa[i]]:=C[x[sa[i]];    Dec (C[x[sa[i]]); End;  fori:=1  toN Dosa[y[i]]:=i; Tot:=1; rank[sa[1]]:=1;  fori:=2  toN Do    begin     if(x[sa[i]]<>x[sa[i-1]])or(x[sa[i]+p]<>x[sa[i-1]+P]) ThenInc (TOT); Rank[sa[i]]:=tot; End; ifTot=n ThenBreak ; P:=p<<1; End;  fori:=1  toN Dosa[rank[i]]:=i; h[1]:=0; p:=0;  fori:=1  toN Do  beginP:=max (P-1,0); ifrank[i]=1  Thencontinue; J:=sa[rank[i]-1];  while(j+p<=n) and(i+p<=n) and(S[i+p]=s[j+p]) DoInc (P); H[rank[i]]:=p; End;End;procedureInit;vari,j,tot,p,m:longint; s1:ansistring;beginReadln (k); Readln (s); fori:=1  toLength (s) Docol[i]:=1; MaxLen:=length (s); fori:=2  toK Do  beginreadln (S1); MaxLen:=max (Length (S1), maxlen); S:=s+'#';  forj:= Length (s) +1  toLength (s) +length (S1) Docol[j]:=i; S:=s+S1; End; N:=length (s); Fillchar (C,sizeof (c),0);  fori:=1  toN Dox[i]:=Ord (s[i]); fori:=1  toN DoInc (C[x[i]); fori:=1  to  -  DoInc (c[i],c[i-1]);  fori:=1  toN Do  beginSa[c[x[i]]:=i;  Dec (C[x[i]]); End; tot:=1; rank[sa[1]]:=1;  fori:=2  toN Do  begin   ifx[sa[i]]<>x[sa[i-1]] ThenInc (TOT); Rank[sa[i]]:=tot; End; make;End;functionCheck (Len:longint): boolean;varI,j,t,cnt:longint;begin  fori:=1  toN Do  begin   ifH[i]<len Then    beginFillchar (lx,sizeof (LX), $7f); Fillchar (rx,sizeof (RX),0); Lx[col[sa[i]]:=Sa[i]; Rx[col[sa[i]]:=Sa[i]; End   Else    beginT:=Col[sa[i]]; LX[T]:=min (lx[t],sa[i]); RX[T]:=Max (rx[t],sa[i]); CNT:=0;  forj:=1  toK Do ifrx[j]-lx[j]+1>=len ThenInc (CNT); ifCnt=k Thenexit (TRUE); End; End; exit (false);End;proceduresolve;varL,r,mid,ans:longint;beginL:=1; R:=maxlen; ans:=0;  whileL<=r Do  beginMid:= (l+r) >>1; ifCheck (mid) Then    beginans:=mid; L:=mid+1; End   Elser:=mid-1; End; Writeln (ans);End; Begin readln (t);  forq:=1  toT Do  beginInit;  Solve End; End.

"SPOJ220" relevant phrases of annihilation (SA)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.