Manacher算法
#include<bits/stdc++.h>
using namespace std;
const int N = 10000;
char s[N];
int p[N];
void Init(string str, char s[]) {
s[0] = '$';
int j = 1;
s[j++] = '#';
for (int i = 0; i < str.size(); i++) {
s[j++] = str[i];
s[j++] = '#';
}
s[j] = '\0';
}
int ManaCher(string str) {
int mx = 0;
int id = 0;
int max = -1;
Init(str, s);
memset(p, 0, sizeof(p));
for (int i = 1; s[i] != '\0'; i++) {
p[i] = mx > i ? min(p[2 * id - i], mx - i) : 1;
while (s[i + p[i]] == s[i - p[i]]) {
p[i]++;
}
if (i + p[i] > mx) {
mx = i + p[i];
id = i;
}
}
for (int i = 0; i < str.size() * 2 + 2; i++){
if (max < p[i] - 1) {
max = p[i] - 1;
}
}
return max;
}
int main() {
string str;
cin >> str;
cout << ManaCher(str) << endl;
return 0;
}