3676: [Apio2014] palindrome string
Time limit:20 Sec Memory limit:128 MB
submit:646 solved:219
[Submit] [Status] [Discuss]
Description
Consider a string s that contains only the lowercase Latin alphabet. We define the "out" of a substring t of s
The present value is the number of occurrences of T in s multiplied by the length of T. Please find out the most in all palindrome strings of S
Large occurrence value.
Input
Enter only one row for a non-empty string s that contains only a lowercase letter (A-Z).
Output
Outputs an integer that is the largest occurrence of a palindrome substring.
Sample Input
"Sample Input L"
Abacaba
"Sample input 2]
Www
Sample Output
"Sample Output L"
7
Sample Output 2]
4
HINT
A string is a palindrome when and only if it reads from left to right and reads from right to left exactly the same.
In the first example, there are 7 palindrome substrings: A,b,c,aba,aca,bacab,abacaba, wherein:
A appears 4 times with a value of 4:1:1=4
B appears 2 times with a value of 2:1:1=2
C appears 1 times with a value of l:1:l=l
ABA appears 2 times with a value of 2:1:3=6
ACA appears 1 times with a value of 1=1:3=3
Bacab appears 1 times with a value of 1:1:5=5
Abacaba appears 1 times with a value of 1:1:7=7
Therefore, the maximum palindrome string occurrence value is 7.
"Data size and scoring"
The data satisfies the 1≤ string length ≤300000.
manacher+ suffix Array ~
The process of calculating the length of palindrome string according to Manacher can be known that the length is n The maximum number of strings in a n A palindrome of different nature.
(Because only the maxid gets bigger, it will produce a different string than the one you just made.)
We just have to be different in nature. O ( n ) A string to calculate their occurrences.
Count occurrences with a suffix array + two points.
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <cstdlib>#define M 600010#define LL Long Longusing namespace STD;intn,wa[m],sa[m],he[m],rk[m],f[m/2][ -],C[M],WB[M],A[M],B[M];intWV[M],P[M];CharS[M];intcmpint*r,intAintBintL) {returnR[A]==R[B]&&R[A+L]==R[B+L];}voidDaint*r,int*sa,intNintm) {int*x=wa,*y=wb,*t,i,j,p; for(i=0; i<m;i++) c[i]=0; for(i=0; i<n;i++) c[x[i]=r[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(j=1, p=1;p <n;j*=2, m=p) { for(p=0, i=n-j;i<n;i++) y[p++]=i; for(i=0; i<n;i++)if(sa[i]>=j) Y[p++]=sa[i]-j; for(i=0; i<n;i++) Wv[i]=x[y[i]]; for(i=0; i<m;i++) c[i]=0; for(i=0; i<n;i++) c[wv[i]]++; for(i=1; i<m;i++) c[i]+=c[i-1]; for(i=n-1; i>=0; i--) Sa[--c[wv[i]]]=y[i]; for(t=x,x=y,y=t,p=1, x[sa[0]]=0, i=1; i<n;i++) x[sa[i]]=cmp (y,sa[i-1],sa[i],j)? p1:p + +; }}voidCalheight (int*r,int*sa,intN) { for(intI=1; i<=n;i++) rk[sa[i]]=i;intk=0; for(intI=0; i<n;i++) {if(k) k--;intj=sa[rk[i]-1]; while(R[i+k]==r[j+k]) k++; He[rk[i]]=k; }}voidGetst () { for(intI=0; i<=n;i++) f[i][0]=he[i]; for(intj=1;(1<<J) <=n;j++) for(intI=0; i+ (1<<J)-1<=n;i++) F[i][j]=min (f[i][j-1],f[i+ (1<< (J-1))][j-1]);}intCalmin (intLintR) {intlen=r-l+1, k=0, now=1; for(intI=0; i<= -; i++) {if(now*2>=len) {k=i; Break; } now<<=1; }returnMin (f[l][k],f[r-(1<<K) +1][k]);}intQuery (intXintK) {intL,R,QL,QR;if(he[x+1]<k) qr=x;Else{l=x+1, R=n; while(L<=R) {intMid= (l+r) >>1;if(Calmin (x+1, mid) >=k) qr=mid,l=mid+1;Elser=mid-1; } }if(he[x]<k) ql=x;Else{l=1, r=x-1; while(L<=R) {intMid= (l+r) >>1;if(Calmin (mid+1, x) >=k) ql=mid,r=mid-1;ElseL=mid+1; } }returnqr-ql+1;}intMain () {scanf('%s ', s); n=strlen(s); for(intI=0; i<n;i++) a[i]=s[i]-' A '+1; a[n]=0; Da (a,sa,n+1, -); Calheight (A,sa,n); GETST (); for(intI=0; i<n;i++) b[i<<1]=a[i]; LL ans=1;intId=0, maxid=-1; for(intI=0;i< (n<<1); i++) {if(maxid>i) P[i]=min (maxid-i,p[2*id-i]);Elsep[i]=1; while(i-p[i]>=0&&b[i+p[i]]==b[i-p[i]]) p[i]++; p[i]--;if(P[I]+I>MAXID) { for(intJ=maxid+1; j<=p[i]+i;j++)if((j&1)==0) {intf=i*2-j;intLen= (j-f+2)/2; Ans=max (ans,1LL*len*query (rk[f>>1],len)); } maxid=p[i]+i,id=i; } }cout<<ans<<endl;return 0;}
"Bzoj 3676" [Apio2014] palindrome string