标签:
Time Limit: 15000MS | Memory Limit: 65536K | |
Total Submissions: 5268 | Accepted: 1896 |
abcbabcbabcba
abacacbaaaab
END
Case 1: 13
Case 2: 6
题解:manacher裸题
CODE:
#include <iostream> #include <cstdio> #include <cstring> #define REP(i, s, n) for(int i = s; i <= n; i ++) #define REP_(i, s, n) for(int i = n; i >= s; i --)] #define max(a, b) a > b ? a : b #define min(a, b) a < b ? a : b #define MAX_N 100000 + 10 using namespace std; char s[(MAX_N << 1) + 1], ts[MAX_N]; int len[(MAX_N << 1) + 1], id = 0; int main(){ while(scanf("%s", ts + 1) != EOF){ if(ts[1] == ‘E‘) break; memset(len, 0, sizeof(len)); int l = strlen(ts + 1); REP(i, 1, l) s[i * 2 - 1] = ts[i]; REP(i, 0, l) s[i * 2] = ‘#‘; l = 2 * l; int ans = 0, mx = 0, pos = 0; REP(i, 0, l){ if(mx > i) len[i] = min(len[(pos << 1) - i], mx - i); else len[i] = 1; while(i - len[i] >= 0 && i + len[i] <= l && s[i + len[i]] == s[i - len[i]]) len[i]++; if(mx < i + len[i]) mx = len[i] + i, pos = i; ans = max(ans, len[i]); } printf("Case %d: %d\n", ++ id, ans - 1); } return 0; }
标签:
原文地址:http://www.cnblogs.com/ALXPCUN/p/4539864.html