# bzoj2160拉拉队排练

bzoj2160拉拉队排练

 1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 #define inc(i,j,k) for(int i=j;i<=k;i++)
5 #define maxn 1000010
6 #define mod 19930726
7 #define ll long long
8 using namespace std;
9
10 int n,mx,id,p[maxn],cnt[maxn]; char s[maxn]; ll ans,k;
11 ll power(ll a,int b){
12     if(b==0)return 1; if(b==1)return a;
13     ll c=power(a,b>>1);
14     if(b&1)return c*c%mod*a%mod;else return c*c%mod;
15 }
16 int main(){
17     scanf("%d%lld",&n,&k); scanf("%s",s+1); mx=0; id=0;
18     inc(i,1,n){
19         if(mx>i)p[i]=min(p[2*id-i],mx-i);else p[i]=1;
20         while(i-p[i]>=1&&i+p[i]<=n&&s[i-p[i]]==s[i+p[i]])p[i]++; cnt[1]++; cnt[2*p[i]+1]--;
21         if(mx<i+p[i]-1)mx=i+p[i]-1,id=i;
22     }
23     inc(i,3,n)if(i&1)cnt[i]+=cnt[i-2]; ans=1;
24     for(int i=n;i>=1;i--){
25         if(cnt[i]){
26             if(k>=cnt[i]){ans=(ans*power(i,cnt[i]))%mod; k-=cnt[i];}else{ans=(ans*power(i,k))%mod; k=0;}
27             if(!k)break;
28         }
29     }
30     if(k)printf("-1");else printf("%lld",ans); return 0;
31 }

20160817

posted @ 2016-08-17 21:49  YuanZiming  阅读(424)  评论(0编辑  收藏  举报