manacher代码有何问题??求解
查看原帖
manacher代码有何问题??求解
1075700
jxjxmmm楼主2024/3/16 19:48
#include<bits/stdc++.h>
using namespace std;
#define int long long
priority_queue<int> q;
const int N=1e6+10;
const int mod=19930726;
char s[N],str[N],n;
int p[N],ans=1;
void inti(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
void manacher()
{
	int len=0;
	str[len++]='@';
//	str[len++]='#';
	for(int i=0;i<strlen(s);i++)
	{
		str[len++]=s[i];
//		str[len++]='#';
	}
	str[len]='\0';
	int mid=0,r=0;
	for(int i=1;i<len;i++)
	{
		if(i<r)
		{
			p[i]=min(p[(mid<<1)-i],r-i+1);
		}
		else
		{
			p[i]=1;
		}
		while(str[i+p[i]]==str[i-p[i]])
		{
			q.push(2*p[i]-1);			
			p[i]++;
		}
		q.push(2*p[i]-1);
		if(i+p[i]>mid) mid=i,r=i+p[i]-1;
//		if((p[i]-1)%2)
//			cnt[p[i]-1]++;
	}
}
signed main()
{
//	inti();
	int M;
//	cin>>n>>M;
	scanf("%d %d\n",&n,&M);
	cin>>s;
	manacher();
	for(int i=1;i<=M;i++)
	{
//		cout<<q.top()<<endl;
		ans=(ans*q.top())%mod;
		q.pop();
	}
	cout<<ans%mod;
}
2024/3/16 19:48
加载中...