模板:manacher算法
C++#include <iostream>
#include <string>
using namespace std;
const int N = 3e7 + 10;
int n,p[N],mid,rt,ans;
string str,s;
inline void manacher()
{
for(int i = 1;i <= n;i ++)
{
if (i < rt) p[i] = min(p[2 * mid - i],rt - i);
else p[i] = 1;
while (s[i + p[i]] == s[i - p[i]]) p[i] ++;
if (i + p[i] > rt) rt = i + p[i],mid = i;
ans = max(ans,p[i] - 1);
}
}
int main()
{
cin >> str;
s += '&';
s += '#';
for(int i = 0;i < str.size();i ++) s += str[i],s += '#';
s += '^';
n = str.size() * 2 + 1;
manacher();
cout << ans << endl;
return 0;
}