-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzfunc.cpp
More file actions
50 lines (50 loc) · 1 KB
/
zfunc.cpp
File metadata and controls
50 lines (50 loc) · 1 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
//God & me // ya mahdi adrekni '-|
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+12,mod=1e9+7;
long long n,m,a[maxn],z[maxn],ans=1;
string s;
int main(){
ios::sync_with_stdio(0);
cin>>n>>m>>s;
if(!m){
for(int i=0;i<n;i++)
ans*=26,ans%=mod;
cout<<ans<<'\n';
return 0;
}
int l=0,r=0;
for(int i=1;i<s.length();i++)
if(r<i){
r=l=i;
while(r<s.length() && s[r-i]==s[r])r++;
z[i]=r-l;
}
else if(z[i-l]<r-i)
z[i]=z[i-l];
else{
l=i;
while(r<s.length() && s[r-i]==s[r])r++;
z[i]=r-l;
}
/*for(int i=0;i<s.size();i++)
cout<<z[i]<<' ';
cout<<'\n';*/
cin>>a[0],a[0]--;
for(int i=1;i<m;i++){
cin>>a[i],a[i]--;
if(z[a[i]-a[i-1]]<a[i-1]+s.length()-a[i])
cout<<"0\n",exit(0);
}
//cout<<":)\n";
int p=0;
for(int i=0;i<a[0];i++)
ans*=26,ans%=mod;
for(int i=0;i<n;i++)
if(p<m-1 && a[p+1]==i)
p++;
else if(a[p]+s.length()<=i)
ans*=26,ans%=mod;
cout<<ans<<'\n';
return 0;
}