标签:class cst turn ... 就是 用处 pac cas 模板题
#include <iostream> #include <cstring> #include <cstdio> #define MAX 110000 using namespace std; int manacher(char *s,int len) { char t[MAX * 2 + 2] = {‘@‘,‘#‘}; int p[MAX * 2 + 2]; int c = 2; for(int i = 0;i < len;i ++) { t[c ++] = s[i]; t[c ++] = ‘#‘; } int rp = 0,rrp = 0,ml = 0; for(int i = 1;i < c;i ++) { p[i] = i < rrp ? min(p[rp - (i - rp)],rrp - i) : 1; while(t[i + p[i]] == t[i - p[i]]) { p[i] ++; } if(rrp < i + p[i]) { rrp = i + p[i]; rp = i; } if(ml < p[i]) { ml = p[i]; } } return ml - 1; } int main() { char s[MAX + 1]; while(~scanf("%s",s)) { printf("%d\n",manacher(s,strlen(s))); } }
标签:class cst turn ... 就是 用处 pac cas 模板题
原文地址:https://www.cnblogs.com/8023spz/p/9751323.html