Rokua P3805 [Template]manacher algorithm [Manacher]

Source: Internet
Author: User

Topic Portal

  

Title Description

A string s consisting of a lowercase English character a,b,c...y,z is given, and the length of the longest palindrome in S is obtained.

String length is n

input/output format

Input format:

A line of lowercase English characters a,b,c...y,z a string s

Output format:

An integer representing the answer

input/Output sampleInput Sample # #:
Aaa
Sample # # of output:
3
Description

String length len <= 11000000

Analysis: Manacher algorithm template, algorithm analysis is not specific, five20 big guy speaks very good, can refer to his blog.

Code:

  

1 //It is made by Holselee on 30th APR 20182 //luogu.org P38053#include <bits/stdc++.h>4 using namespacestd;5 Const intn=2e7+3e6+7;6 CharS[n],neo[n];intP[n];7 intChange ()8 {9   intlen=strlen (s);Ten   intret=0; neo[ret++]='$'; One    for(intI=0; i<len;i++) Aneo[ret++]='#', neo[ret++]=S[i]; -neo[ret++]='#'; neo[++ret]=' /';returnret; - } the intManacher () - { -   intlen=Change (); -   intans=-n,id,mx=0; +    for(intI=1; i<=len;i++){ -     if(I&LT;MX) P[i]=min (p[id*2-i],mx-i); +     Elsep[i]=1; A      while(Neo[i-p[i]]==neo[i+p[i]]) p[i]++; atAns=max (ans,p[i]-1); -     if(I+P[I]&GT;MX) id=i,mx=i+P[i]; -   } -   returnans; - } - intMain () in { -scanf"%s", s); toprintf"%d", Manacher ()); +   return 0; -}

Rokua P3805 [Template]manacher algorithm [Manacher]

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.