Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
ExKmp不行么?WA了。。 #include <iostream> #define MAXL 500000 using namespace std; char s[MAXL]; int next[MAXL]; int k; int far; int main(){ int i; while (scanf(" %s", s) != EOF){ k = 0; for (i=1; s[i]!='\0'; i++){ if (k <= 0 || (far = k + next[k] - 1) < i){ next[i] = 0; while (s[i + next[i]] == s[next[i]]) next[i]++; } else{ if (next[i - k] > far - i + 1){ next[i] = far - i + 1; while (s[i + next[i]] == s[next[i]]) next[i]++; } else next[i] = next[i - k]; } if (k <= 0 || far < i + next[i] - 1) k = i; } next[0] = i; for (i=0; i<next[0]-1; i++){ if (next[next[0] - i - 1] == i + 1) printf("%d ", i + 1); } printf("%d\n", next[0]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator