fork(5) download
  1. #include <iostream>
  2. using namespace std;
  3. const int MOD = 1000000007;
  4. const int MAX = 1000005;
  5. int a[MAX], z[MAX], q[MAX];
  6. int main()
  7. {
  8. ios::sync_with_stdio(false);
  9. int n, m;
  10. cin >> n >> m;
  11. string s;
  12. cin >> s;
  13. int l = 0, r = 0;
  14. z[0] = s.size();
  15. for (int i = 1; i < s.size(); i++)
  16. if (r <= i)
  17. {
  18. l = r = i;
  19. while (r < n && s[r - l] == s[r])
  20. r++;
  21. z[i] = r - l;
  22. }
  23. else
  24. {
  25. int k = i - l;
  26. if (z[k] < r - i)
  27. z[i] = z[k];
  28. else
  29. {
  30. l = i;
  31. while (r < n && s[r - l] == s[r])
  32. r++;
  33. z[i] = r - l;
  34. }
  35. }
  36. for (int i = 0; i < m; i++)
  37. {
  38. cin >> q[i];
  39. q[i]--;
  40. a[q[i]]++;
  41. a[q[i] + s.size()]--;
  42. }
  43. for (int i = 1; i < m; i++)
  44. {
  45. int len = q[i - 1] + s.size() - q[i];
  46. if (len <= 0)
  47. continue;
  48. if (z[s.size() - len] < len)
  49. {
  50. cout << "0\n";
  51. return 0;
  52. }
  53. }
  54. int ans = 1;
  55. for (int i = 0; i < n; i++)
  56. {
  57. if (i)
  58. a[i] += a[i - 1];
  59. if (!a[i])
  60. ans = 1LL * ans * 26 % MOD;
  61. }
  62. cout << ans << endl;
  63. return 0;
  64. }
Runtime error #stdin #stdout 0.1s 14952KB
stdin
Standard input is empty
stdout
Standard output is empty