HDU - 3068 最长回文
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
const int N=1010;
int Manacher(string s)
{
if(s.size() <= 1) return 1;string str = "@#";for(int i = 0;i < s.size();i++) {
str += s[i];str += '#';}vector<int> p(str.size(),0);int mx = 0, id = 0,start = 0,maxlen = 0; for (int i = 1; str[i] != '\0'; i++) {
p[i] = mx > i ? min(p[2 * id - i], mx - i) : 1;while (str[i + p[i]] == str[i - p[i]]) p[i]++;if (i + p[i] > mx) {
mx = i + p[i];id = i;}if(p[i]-1 > maxlen){
start = (i-p[i])/2;maxlen = p[i]-1;}}return s.substr(start,maxlen).size();
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);string str;while(cin>>str){
cout<<Manacher(str)<<endl;}return 0;
}