标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2028 Accepted Submission(s): 819
1 /**/ 2 #include<iostream> 3 #include<cstdio> 4 #include<cmath> 5 #include<cstring> 6 #include<algorithm> 7 using namespace std; 8 const int mxn=1000200; 9 char s[mxn]; 10 char c[mxn]; 11 int w[30]; 12 int p[mxn],sum[mxn]; 13 int len,ans=0; 14 void mana(){ 15 int id=0,mx=0; 16 int i,j; 17 for(i=1;i<len;i++){ 18 if(mx>i)p[i]=min(p[2*id-i],p[id]+id-i); 19 else p[i]=0; 20 while(s[i+p[i]]==s[i-p[i]])p[i]++; 21 if(p[i]+i>mx){ 22 mx=p[i]+i; 23 id=i; 24 } 25 } 26 return; 27 } 28 int main(){ 29 int T; 30 scanf("%d",&T); 31 int i,j; 32 while(T--){ 33 for(i=0;i<26;i++)scanf("%d",&w[i]); 34 scanf("%s",c+1); 35 len=strlen(c+1); 36 sum[0]=0; 37 for(i=1;i<=len;i++)sum[i]=sum[i-1]+w[c[i]-‘a‘]; 38 s[0]=‘$‘;s[1]=‘#‘; 39 for(i=1;i<=len;i++){s[i*2]=c[i];s[i*2+1]=‘#‘;} 40 len=len*2+2;s[len]=‘@‘; 41 mana(); 42 ans=0; 43 len=(len-2)/2; 44 for(i=1;i<len;i++){ 45 int tmp=0; 46 int l=(1+i*2+1)/2,r=(i*2+1+len*2+1)/2; 47 if(p[l]>=i*2+1-l) tmp+=sum[i]; 48 if(p[r]>=r-(i*2+1))tmp+=sum[len]-sum[i]; 49 // printf("i:%d tmp:%d\n",i,tmp); 50 ans=max(ans,tmp); 51 } 52 printf("%d\n",ans); 53 } 54 }
标签:
原文地址:http://www.cnblogs.com/SilverNebula/p/5883437.html