题目链接:【模板】manacher 算法 - 洛谷
题面:
就是马拉车模板没了
//求最长回文子串的长度
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define MAXN 11000010
char Ma[MAXN * 2];
int Mp[MAXN * 2];
void Manacher(string s, int len){
int l = 0;
Ma[l++] = '$';
Ma[l++] = '#';
for(int i = 0; i < len; i++){
Ma[l++] = s[i];
Ma[l++] = '#';
}
Ma[l] = 0;
int mx = 0, id = 0;
for(int i = 0; i < l; i++){
Mp[i] = mx > i ? min(Mp[2 * id - i], mx - i) : 1;
while(Ma[i + Mp[i]] == Ma[i - Mp[i]]){
Mp[i]++;
}
if(i + Mp[i] > mx){
mx = i + Mp[i];
id = i;
}
}
}
int main(){
ios::sync_with_stdio(false);
string s;
while(cin >> s){
int len = s.length();
Manacher(s, len);
int ans = 0;
for(int i = 0; i < 2 * len; i++){
ans = max(ans, Mp[i] - 1);
}
cout << ans << endl;
}
return 0;
}