manacher
感受一下两种不同的码风
第一种是我的正常码风
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<iostream>
using namespace std;
const int N =41000010;
char s[N],news[N<<1];
int p[N],len;
inline int read(){
int f=0,x=0;
char ch=getchar();
while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return f?-x:x;
}
inline int init(){
int len=strlen(s);
news[0]='$';
news[1]='#';
int j=2;
for(register int i=0;i<len;++i){
news[j++]=s[i];
news[j++]='#';
}
news[j++]='\0';
return j;
}
inline int manacher(){
int newlen=init(),maxlen=-1,id,mx=0;
for(register int i=1;i<newlen;++i){
if(i<mx) p[i]=min(p[id*2-i],mx-i);
else p[i]=1;
while(news[i-p[i]]==news[i+p[i]]) p[i]++;
if(mx<i+p[i]){
id=i;
mx=i+p[i];
for(register
}
maxlen=max(maxlen,p[i]-1);
}
return maxlen;
}
signed main(){
scanf("%s",s);
printf("%d",manacher());
return 0;
}
第二种是我闲来无事仿大神的码风
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 11000010;
char s[N] ,s_new[N<<1];
int len ,p[N];
inline int read(){
int f=0,x=0;
char ch=getchar();
while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return f?-x:x;
}
inline init(){
int len = strlen(s);
s_new[0] = '$';
s_new[1] = '#';
int j = 2;
for(register int i = 0;i < len; ++i){
s_new[j++] = s[i];
s_new[j++] = '#';
}
s_new[j++] = '\0';
return j ;
}
inline int manacher(){
int newlen = init();
int maxlen = -1;
int id;
int mx = 0;
for(register int i = 1;i < newlen; ++i){
if(i < mx)
p[i] = min(p[id * 2 - i],mx - i);
else
p[i] = 1;
while(s_new[i - p[i]] == s_new[i + p[i]])
p[i]++;
if(mx < i + p[i]){
id = i;
mx = i + p[i];
}
maxlen = max(maxlen ,p[i] - 1);
}
return maxlen;
}
signed main(){
scanf("%s",s);
printf("%d",manacher());
return 0;
}