fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
  4. typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll;
  5. typedef vector<pll> vpll;typedef vector<string> vs; typedef double D; typedef vector<bool> vb;
  6. typedef pair<ll,pll> pip;
  7. #define sz(v) int((v).size())
  8. #define all(v) (v).begin(), (v).end()
  9. #define pb push_back
  10. #define mp make_pair
  11. #define F first
  12. #define S second
  13. #define sd(x) scanf("%d", &x)
  14. #define slld(x) scanf("%I64d", &x)
  15. #define debug(X) cerr << " --> " << #X << " = " << X << endl
  16. #define present(c,x) ((c).find(x) != (c).end())
  17. #define mod 1000000007LL
  18. #define INF 2000000000LL
  19. #define N 1123456
  20. char p[N];
  21. int st[N],f[N],ar[N],po[N];
  22. int findset(int a)
  23. {
  24. if(st[a]==a)return a;
  25. return st[a] = findset(a);
  26. }
  27. void mergeset(int a,int b)
  28. {
  29. if(st[a]==st[b])return;
  30. int x = findset(a);
  31. int y = findset(b);
  32. st[y] = x;
  33. }
  34. int main()
  35. {
  36.  
  37. int n,m;
  38. cin>>n>>m;
  39. cin>>p;
  40. po[0] = 1;
  41. for(int i=1;i<=n;++i)
  42. {
  43. po[i] = po[i-1]*26;
  44. if(po[i]>=mod) po[i] %= mod;
  45. }
  46. int len = strlen(p);
  47. for(int i=1;i<=m;++i)
  48. {
  49. cin>>ar[i];
  50. }
  51. sort(ar,ar+m);
  52. f[0] = f[1] = 0;
  53. for(int i=2;i<=len;++i)
  54. {
  55. for(int j=f[i-1];;j=f[j])
  56. {
  57. if(p[j]==p[i-1])
  58. {
  59. f[i] = j + 1;
  60. break;
  61. }
  62. if(j==0)
  63. {
  64. f[i] = 0;
  65. break;
  66. }
  67. }
  68. }
  69. for(int i=0;i<=len;++i) st[i] = i;
  70. for(int i=0;i<=len;++i)
  71. {
  72. mergeset(f[i],f[f[i]]);
  73. }
  74. ll ans = 1;
  75. if(ar[m]+len-1>n){printf("0\n");return 0;}
  76. else ans = (ans*po[n-ar[m]-len+1])%mod;
  77. int k;
  78. for(int i=m-1;i>0;--i)
  79. {
  80. if(ar[i]+len-1>=ar[i+1])
  81. {
  82. k = ar[i]+len-ar[i+1];
  83. if(!(st[f[len]]==st[k]&&f[len]>=k)){printf("0\n");return 0;}
  84. }
  85. else
  86. {
  87. ans = (ans*po[ar[i+1]-ar[i]-len])%mod;
  88. }
  89. }
  90. ans = (ans*po[ar[1]-1])%mod;
  91. printf("%I64d\n",ans);
  92. return 0;
  93. }
  94.  
Success #stdin #stdout 0s 21752KB
stdin
6 2
ioi
1 3
stdout
                                                              26