1040. Longest shortric String (25) Longest echo substring-Marathon (manacher algorithm) -- PAT (Advanced Level) Practise

Source: Internet
Author: User

1040. Longest shortric String (25) Longest echo substring-Marathon (manacher algorithm) -- PAT (Advanced Level) Practise
Question Information

1040. Longest shortric String (25)

Time limit 400 MS
The memory limit is 65536 kB.
Code length limit: 16000 B

Given a string, you are supposed to output the length of the longest distributed Ric sub-string. For example, given "Is PAT & TAP distributed Ric ?", The longest specified Ric sub-string is "s PAT & TAP s", hence you must output 11.

Input Specification:

Each input file contains one test case which gives a non-empty string of length no more than 1000.

Output Specification:

For each test case, simply print the maximum length in a line.

Sample Input:
Is PAT & TAP into Ric?
Sample Output:
11

Solutions

Manacher algorithm, do not understand can refer to my another blog: http://blog.csdn.net/xianyun2009/article/details/46767829

AC code
# Include
  
   
# Include using namespace std; char s [2010]; int r [2010]; int ch, p = 0; int manacher () {int cn = 0, mx = 0, re = 0; for (int I = 1; I <p; ++ I) {r [I] = (mx> I )? Min (r [cn * 2-I], mx-I): 1; while (s [I + r [I] = s [I-r [I]) + + r [I]; if (I + r [I]> mx) {mx = I + r [I]; cn = I;} if (r [I]> re) re = r [I];} return re-1;} int main () {s [p ++] = '\ 1 '; // special character while (ch = getchar () & ch! = '\ N') {s [p ++] =' \ 3'; s [p ++] = ch ;} s [p ++] = '\ 3'; printf ("% d \ n", manacher (); return 0 ;}
  

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.