-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path536b-z.cpp
More file actions
72 lines (71 loc) · 1.42 KB
/
536b-z.cpp
File metadata and controls
72 lines (71 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int MAXN = 1e6+5;
const int mul = 9997;
long long h[MAXN];
long long p[MAXN];
string s;
vector<int>Z() {
int L = 0, R = 0;
vector<int>z(s.size());
z[0] = s.size();
for (int i = 1 ; i < s.size() ; i++) {
if (i <= R) {
z[i] = z[i - L];
}
else {
L = i;
if (i > R) {
R = i;
}
while (R < z[0] && s[R - L] == s[R]) R++;
z[i] = (R--) - L;
}
}
return z;
}
void go() {
int n, k;
cin >> n >> k;
cin >> s;
auto z = Z();
int f = 1;
int cnt = 0;
for (int i = 0; i < k; i++) {
int pos;
cin >> pos;
cnt += max(0,pos - f);
//cout << pos - f << endl;
if (pos - f < 0 && z[z.size()-f+pos] < f - pos) {
//cout << pos <<' '<<f<<' '<<z.size()-f+pos<<endl;
cout << 0 << '\n';
return;
}
f = pos + s.size();
//cout << cnt << endl;
}
cnt += n + 1 - f;
//cout << cnt << endl;
long long ans = 1;
for (int i = 0; i < cnt; i++) {
ans *= 26;
ans %= mod;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int c = 0;
int t;
if (!c) {
t = 1;
}
else {
cin >> t;
}
while (t--) {
go();
}
}