UESTC Search Topic m topic palindromic String Horse-drawn vehicle algorithm

Source: Internet
Author: User

Palindromic String

Time limit:20 Sec Memory limit:256 MB

Topic Connection HTTP://ACM.UESTC.EDU.CN/#/CONTEST/SHOW/61
Description

Qiushi Big Brother likes to explore new things, recently he invented a new palindrome string, called K-heavy palindrome string! Today he wants to use it to test the children.

Qiushi the information about the K-heavy palindrome string.

Any string belongs to a 0 palindrome string, including an empty string.
A string of length n s,s is a K (k≥1) re-palindrome string, when and only if S is a palindrome string, and its length is ⌊n2⌋ prefix and the length of the ⌊n2⌋ suffix is k−1 heavy palindrome string.
If a string is a K-palindrome string, the string is said to have a palindrome value of K. A string can have more than one palindrome value, such as S=abaaba, its palindrome value can be 0,1,2,3.
The maximum palindrome value of a string is the maximum value of all palindrome values for that string.
If the maximum palindrome value of the string s ≥1, then s must be a palindrome string.
A string s, if it is the same as read and reverse read, it is called S is palindrome string, such as Aabaa,aba,a. But ABC,ABAB,AACBA is not a palindrome.
A string of length n s, which has n+1 prefixes and n+1 suffixes (not necessarily non-null), such as ABCDE, has 6 prefixes, respectively, is an empty string, A,AB,ABC,ABCD,ABCDE, there are 6 suffixes, respectively, is an empty string, E,DE,CDE,BCDE,ABCDE.

Qiushi Big Brother gives you a string s, he wants to ask you, s the maximum palindrome for all prefixesa is completely coincident, or can be shifted up or down by a line < Span id= "mathjax-span-1329" class= "math" style= "WIDTH:0.958EM; Display:inline-block; " >a a section of the complete coincidence, it means that Qiushi Big Brother blew out a part of the melody of her sister. Input first line Enter a string s (0<| s|≤2⋅106), S contains uppercase English letter (A-Z), lowercase English letter (A-Z), number (0-9) Output

Outputs an integer that represents the sum of the maximum palindrome values for all prefixes in S .

Sample InputCcececccee
Sample Output4hint

Test Instructions

Exercises

First run the horse-drawn cart algorithm, and then get all the characters of the P array, indicating the length of the palindrome string
And then we'll solve it recursively.
And then you know that each palindrome is a few heavy
(although I think the complexity may be very high, but run quickly, do not know why ...)

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 2000010#defineMoD 10007#defineEPS 1e-9intNum;Charch[ -];//const int INF=0X7FFFFFFF; //нчоч╢сConst intinf=0x3f3f3f3f;/*inline void P (int x) {num=0;if (!x) {Putchar (' 0 ');p UTS (""); return;}    while (x>0) ch[++num]=x%10,x/=10;    while (Num) Putchar (ch[num--]+48); Puts ("");}*/inline ll read () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;} InlinevoidPintx) {Num=0;if(!x) {Putchar ('0');p UTS ("");return;}  while(x>0) ch[++num]=x%Ten, x/=Ten;  while(Num) Putchar (ch[num--]+ -); Puts ("");}//**************************************************************************************CharS[MAXN];Charstr[maxn*2];intl;intp[maxn*2];intManacher (CharS[],intl) {   inti,j,k,ans=0;  for(i=1; i<=l;++i) str[i<<1]=s[i],str[(i<<1)+1]='#'; str[1]='#'; str[l*2+1]='#'; str[0]='&'; str[l*2+2]='$'; L=l*2+1; j=0;  for(i=1; i<=l;) {        while(str[i-j-1]==str[i+j+1])++J; P[i]=j;if(J>ans) ans=J;  for(k=1; k<=j&&p[i]-k!=p[i-k];++k) P[i+k]=min (p[i-k],p[i]-k); I+=k;j=max (J-k,0); }   returnans;}intMain () {scanf ("%s", s+1); L=strlen (s+1);    Manacher (s,l); L=l*2+1; intans=0;  for(intI=2; i<= (L +1)/2; i++)    {        inttmp=P[i]; intpos=i;  while(tmp+1>=pos&&tmp!=0) {ans++; POS= (pos+1)/2; TMP=P[pos]; }        //cout<<ans<<endl;} cout<<ans<<Endl;}

UESTC Search Topic m topic palindromic String Horse-drawn vehicle algorithm

Related Article

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.