Skip to content

Commit

Permalink
20240617 lengli's submission for CF535D (Yawn-Sean#3700)
Browse files Browse the repository at this point in the history
20240617 lengli's submission for CF535D
  • Loading branch information
gxylengli authored Jun 17, 2024
1 parent b37e542 commit f9f366f
Showing 1 changed file with 126 additions and 0 deletions.
126 changes: 126 additions & 0 deletions daily_problems/2024/06/0617/personal_submission/cf535d_lengli.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
lengli_QAQ
Hope there are no bugs!!!
*/
#include <bits/stdc++.h>
#define fastio std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0)
#define all(x) x.begin(),x.end()
#define pb push_back

template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
bool operator<(const ModInt &a) const { return (x < a.x); }
bool operator>(const ModInt &a) const { return (x > a.x); }
bool operator<=(const ModInt &a) const { return (x <= a.x); }
bool operator>=(const ModInt &a) const { return (x >= a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
friend std::istream &operator>>(std::istream &is, ModInt &a) {int v;is >> v;a = ModInt(v);return is;}
};
constexpr unsigned MO = 1000000007;
using Mint = ModInt<MO>;

std::vector<int> z_function(std::string s){
int n = (int)s.size();
std::vector<int> z(n);
for (int i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r && z[i - l] < r - i + 1) {
z[i] = z[i - l];
} else {
z[i] = std::max(0, r - i + 1);
while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
}
if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
}
return z;
}

void solve(){
int n,m;
std::cin>>n>>m;
std::string s;
std::cin>>s;
int len=s.size();
std::vector<int> idx(m);
for(auto &x:idx) std::cin>>x;
auto z=z_function(s);

sort(all(idx));

if(!m){
std::cout<<Mint(26).pow(n)<<"\n";
return;
}

if(idx[0]+len-1>n){
std::cout<<0<<"\n";
return;
}

int cnt=idx[0]-1;
int la=idx[0];
for(int i=1;i<m;i++){
int t=idx[i];
if(t-la>=len) {
cnt+=(t-(la+len));
if(t+len-1>n){
std::cout<<0<<"\n";
return;
}
la=t;
}else{
int k=z[t-la],nd=(len-(t-la));
if(k>=nd) {
la=t;
continue;
}else {
std::cout<<0<<"\n";
return;
}

}
}
cnt+=(n-(la+len-1));
std::cout<<Mint(26).pow(cnt)<<"\n";
}

signed main(){
fastio;

int T;
T=1;
while(T--) solve();

return 0;
}

0 comments on commit f9f366f

Please sign in to comment.