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