Bzoj2882 process [Hong Kong algorithm]

Source: Internet
Author: User

Suffix automata-http://www.cnblogs.com/SilverNebula/p/6420601.html

Suffix automatic machine knocked over, looked at the next line, WC why others run so fast? ...... Yes, the minimum notation with the suffix automaton is of course slow.

Vaguely remember the minimum notation has an ultra-fast algorithm, so went to check, there is an O (n) algorithm (suffix automaton is also O (n) but constant large)

Find this tutorial, http://www.cnblogs.com/mjy0724/p/4625928.html

So run fast (380ms, do not know how those dozens of Ms How to run out of)

1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7 using namespacestd;8 Const intmxn=600010;9 intRead () {Ten     intx=0, f=1;CharCh=GetChar (); One      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} A      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnx*F; - } the intN,A[MXN]; - intsolve () { -     inti,j,ed=n*2; -I=1; j=2; +      while(I<=n && j<=N) { -         intk=0; +          while(j+k<=ed && a[i+k]==a[j+k]) k++; A         if(j+k>ed) Break; at         if(a[i+k]>a[j+K]) { -I=max (j,i+k+1); -j=i+1; -         } -         Elsej=j+k+1; -     } in     returnmin (i,j); - } to intMain () { +     inti,j; -n=read (); the      for(i=1; i<=n;i++){ *A[i]=read (); a[i+n]=A[i]; $     }Panax Notoginseng     intans=solve (); -     inted=ans+n-1; the      for(i=ans;i<ed;i++) printf ("%d", A[i]); +printf"%d\n", a[ed]); A     return 0; the}

Bzoj2882 process [Hong Kong algorithm]

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.