直接上板子
直接输出最长回文子序列的长度
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
char s[32000005],st[32000005];
int p[32000005];
int change()
{
int len=strlen(st);
int j=2;
s[0]='^';
s[1]='$';
for (int i=0;i<len;i++)
{
s[j++]=st[i];
s[j++]='$';
}
s[j]='&';
return j;
}
int Manacher()
{
int len=change(),mid=1,mx=1,ans=-1;
for (int i=1;i<len;i++)
{
if (i<mx)
p[i]=min(mx-i,p[mid*2-i]);
else
p[i]=1;
while (s[i-p[i]]==s[i+p[i]])
p[i]++;
if (mx<i+p[i])
{
mid=i;
mx=i+p[i];
}
ans=max(ans,p[i]-1);
}
return ans;
}
signed main(){
IOS
int T=1;
//cin>>T;
while(T--)
{
cin>>st;
cout<<Manacher();
}
}
标签:cout,int,st,Mananer,序列,回文,32000005,拉车
From: https://www.cnblogs.com/yzzyang/p/18141952