Hdu 3068 Manacher algorithm O (n) echo substring Algorithm

Source: Internet
Author: User

Question: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 3068

About the algorithm of the tutorial recommended this: http://blog.csdn.net/ggggiqnypgjg/article/details/6645824 attention: I recommend this blog said that the code has a bug, I think no problem, but the blog was wrong when using, I have passed the reversed example and the hdu 3068 has passed.

The suffix array is used at the beginning, 2000 ms + decisive timeout ...............

I read this algorithm once and quickly learned it: Then A drops

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Define MAXN 200010 using namespace std; int p [MAXN], n; char str [MAXN], s [MAXN]; void pk () {int mx = 0, id; for (int I = n; str [I]! = 0; I ++) str [I] = 0; for (int I = 1; I
       
         I) p [I] = min (p [id * 2-i], mx-I); // write min (id * 2-i, mx-I) Here ), WA makes me vomit, But the strange thing is that it can run 328 ms else p [I] = 1; while (str [I-p [I] = str [I + p [I]) p [I] ++; if (I + p [I]> mx) {mx = p [I] + I; id = I ;}} void init () {int I, j; n = strlen (s); str [0] = '$'; // start with a flag. Other characters that do not appear in the test sample can be used, it also ensures that the p [I] calculation will not cross the border, and the null character is definitely not equal to $ str [1] = '#'; // interval, you can use other characters for (I = 0, j = 2; I
        
         



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.