# [BZOJ2160]拉拉队排练

Description

Input

Output

Sample Input
5 3
ababa

Sample Output
45

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')    f=-1;
for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10)     print(x/10);
putchar(x%10+'0');
}
const int N=1e6,P=19930726;
char s[N*2+10];
int p[N*2+10],cnt[N*2+10];
int mlt(int a,int b){
int res=1;
for (;b;b>>=1,a=1ll*a*a%P)	if (b&1)	res=1ll*res*a%P;
return res;
}
int main(){
ll k;
scanf("%lld%s",&k,s+1);
for (int i=len;i;i--)	s[i<<1]=s[i],s[i<<1|1]='&';
len=len<<1|1;
s[0]='#',s[1]='&',s[len+1]='^';
int Max=0,ID=0,ans=1;
for (int i=1;i<=len;i++){
p[i]=Max>i?min(p[ID*2-i],Max-i):1;
while (s[i+p[i]]==s[i-p[i]])	p[i]++;
if (Max<p[i]+i)	Max=p[ID=i]+i;
}
for (int i=2;i<len;i+=2)	cnt[p[i]/2]++;
for (int i=len/2;i;i--)		cnt[i]+=cnt[i+1];
for (int i=len/2;i;i--){
if (k>cnt[i])	k-=cnt[i],ans=1ll*ans*mlt(i*2-1,cnt[i])%P;
else{
ans=1ll*ans*mlt(i*2-1,k)%P;
break;
}
}
printf("%d\n",ans);
return 0;
}


posted @ 2018-02-04 21:52  Wolfycz  阅读(264)  评论(0编辑  收藏  举报