标签:while efi scanf tar space nan target char s algo
Code:
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; #define setIO(s) freopen(s".in","r",stdin) #define maxn 2300000 #define mod 19930726 #define ll long long char str[maxn],s[maxn]; int p[maxn],maxv; ll arr[maxn],brr[maxn],k; int Init(){ int len=strlen(s),j=1; str[0]=‘$‘,str[1]=‘#‘; for(int i=0;i<len;++i)str[++j]=s[i],str[++j]=‘#‘; str[++j]=‘\0‘; return j; } void solve(){ int len=Init(),id=1,mx=1; for(int i=1;i<len;++i){ if(i<mx) p[i]=min(p[2*id-i],mx-i); else p[i]=1; while(str[i-p[i]]==str[i+p[i]]) ++p[i]; if(p[i]+i>mx) mx=p[i]+i,id=i; if(str[i]!=‘#‘) { arr[1]+=1,arr[p[i]+1]-=1; maxv=max(maxv,p[i]); } } } ll qpow(ll a,ll p){ ll res=1; while(p){ if(p&1) res*=a,res%=mod; a*=a,a%=mod; p>>=1; } return res; } int main(){ //setIO("input"); int n; ll k,ans=1; scanf("%d%lld",&n,&k); scanf("%s",s); solve(); for(int i=1;i<=maxv;++i) arr[i]+=arr[i-1]; for(int i=1;i<=maxv;++i) if(i%2==0&&arr[i]) brr[i-1]=arr[i]; for(int i=maxv;i>=1;--i){ if(!arr[i]) continue; ans*=qpow(i,min(brr[i],k)),ans%=mod; //printf("%d %lld\n",i,ans); k-=brr[i]; if(k<=0) break; } if(k>0) printf("-1"); else printf("%lld",ans); return 0; }
[国家集训队]拉拉队排练 Manancher_前缀和_快速幂
标签:while efi scanf tar space nan target char s algo
原文地址:https://www.cnblogs.com/guangheli/p/10264916.html