蒟蒻manacher92pts求助
查看原帖
蒟蒻manacher92pts求助
178556
Skyjoy楼主2020/5/4 19:35

WA了第二个点qwq,调了好久了

代码:

#include<bits/stdc++.h>
#define N 1000010
using namespace std;
int n,f[N],ans;
char s[N];
void manacher(int x){
	int mid=0,maxn=0;
	for(int i=1;i<=x;i+=2){
		f[i]=(maxn>i)?min(f[2*mid-i],maxn-i):1;
		if(maxn>i&&i-f[i]<mid){
			ans=max(ans,2*(i-mid));
		}
		while(s[i+f[i]]==s[i-f[i]]){
			f[i]++;
		}
		if(f[i]+i>maxn){
			mid=i,maxn=f[i]+i;
		}
	}
}
int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return x;
}
int main(){
	n=read();
	scanf("%s",s+1);
	s[1]='$';
	for(int i=n;i;i--){
		s[i*2+1]='$',s[i*2]=s[i];
	}
	manacher(2*n);
	printf("%d",ans);
	return 0;
}
2020/5/4 19:35
加载中...