80挂科
查看原帖
80挂科
836448
stylus楼主2024/9/28 19:48

原因:厌氧
代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
void read(int &x){
	x=0;bool f=0;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-')f=1;
		ch=getchar();
	}do{x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}while(ch>='0'&&ch<='9');
	x=f?-x:x;
}
int n,p[20000001],ans;
string s,e;
void add(){
	e="^";
	for(int i=0;i<s.size();i++){
		p[i]=1,e+="#",e+=s[i];
		while(s[i+p[i]]==s[i-p[i]])p[i]++;
	}e+="#@";
	return;
}
void manacher(){
	int r=0,mid=0;
	add(),ans=0;
	for(int i=1;i<e.size()-1;i++){
		p[i]=r>i?min(p[2*mid-i],r-i):1;
		while(e[i+p[i]]==e[i-p[i]])p[i]++;
		if(i+p[i]>r)r=i+p[i],mid=i;
		ans=max(p[i],ans);
	}cout<<ans-1<<endl;
}
signed main(){
	read(n);
	while(n--)cin>>s,manacher();
	return 0;
}
2024/9/28 19:48
加载中...