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]