标签:
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 14761 | Accepted: 7407 |
Description
Input
Output
Sample Input
ababcababababcabab aaaaa
Sample Output
2 4 9 18 1 2 3 4 5
Source
#include <cstdio> using namespace std; const int N(4e5+5); char s[N]; int nt[N], ans[N]; int main(){ for(int ls, cnt; ~scanf("%s", s);){ for(int i=ls=1, k=0; s[i]; i++, ls++){ while(k&&s[k]!=s[i]) k=nt[k-1]; nt[i]=s[k]==s[i]?++k:k; } for(int i=(cnt=0,ls); i; ans[cnt++]=i, i=nt[i-1]); for(; cnt; printf("%d ", ans[--cnt])); puts(""); } }
代码有亮点
for(int i=(cnt=0,ls); i; ans[cnt++]=i, i=nt[i-1]);
POJ 2752 Seek the Name, Seek the Fame
标签:
原文地址:http://www.cnblogs.com/Patt/p/4921953.html