Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define maxn 1000010
  4. #define ll long long
  5. const int mod=1e9+7;
  6. const int c=26;
  7. const int p=101;
  8. const int Mod=1e9+7;
  9. int n,k;
  10. char s[maxn];
  11. ll pw(ll a,int n)
  12. {
  13. ll res=1;
  14. while(n)
  15. {
  16. if(n&1)res=res*a%mod;
  17. a=a*a%mod,n>>=1;
  18. }
  19. return res;
  20. }
  21. ll INV(ll a){return pw(a,mod-2);}
  22. int main()
  23. {
  24. scanf("%d%d",&n,&k);
  25. scanf("%s",s);
  26. ll pre=0,suf=0;
  27. ll ans=0;
  28. ll pp=1;
  29. for(int i=0;i<n;i++)
  30. {
  31. pre=(pre*p+(s[i]-'a'))%Mod,suf=(suf+pp*(s[n-i-1]-'a'))%Mod;
  32. pp=pp*p%Mod;
  33. if(pre==suf && 2*n-(i+1)<=k)ans++;
  34. }
  35. if(k>=2*n)
  36. {
  37. /*
  38. int m=k-2*n;
  39. ll tmp=pw(c,m+1);
  40. tmp=(tmp-1+mod)%mod;
  41. tmp=tmp*INV(c-1)%mod;
  42. ans=(ans+tmp)%mod;
  43. */
  44. int m=k-2*n;
  45. ll cur=1;
  46. for(int i=0;i<=m;i++)
  47. {
  48. ans=(ans+cur)%mod;
  49. cur=cur*c%mod;
  50. }
  51. }
  52. printf("%lld\n",ans);
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement