Submission #492773

#TimeUsernameProblemLanguageResultExecution timeMemory
492773maksim1744Lucky Numbers (RMI19_lucky)C++17
28 / 100
1 ms460 KiB
/* author: Maksim1744 created: 09.12.2021 00:29:14 */ #include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; #define mp make_pair #define pb push_back #define eb emplace_back #define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) template<typename T> vector<T>& operator-- (vector<T> &v){for (auto& i : v) --i; return v;} template<typename T> vector<T>& operator++ (vector<T> &v){for (auto& i : v) ++i; return v;} template<typename T> istream& operator>>(istream& is, vector<T> &v){for (auto& i : v) is >> i; return is;} template<typename T> ostream& operator<<(ostream& os, vector<T> v){for (auto& i : v) os << i << ' '; return os;} template<typename T, typename U> pair<T,U>& operator-- (pair<T, U> &p){--p.first; --p.second; return p;} template<typename T, typename U> pair<T,U>& operator++ (pair<T, U> &p){++p.first; ++p.second; return p;} template<typename T, typename U> istream& operator>>(istream& is, pair<T, U> &p){is >> p.first >> p.second; return is;} template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U> p){os << p.first << ' ' << p.second; return os;} template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);} template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);} template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;} template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;} #ifdef HOME #define SHOW_COLORS #include "/mnt/c/Libs/tools/print.cpp" #else #define show(...) void(0) #define debugf(fun) fun #define debugv(var) var #define mclock void(0) #define shows void(0) #define debug if (false) #endif namespace mint_ns { template<auto P> struct Modular { using value_type = decltype(P); value_type value; Modular(long long k = 0) : value(norm(k)) {} friend Modular<P>& operator += ( Modular<P>& n, const Modular<P>& m) { n.value += m.value; if (n.value >= P) n.value -= P; return n; } friend Modular<P> operator + (const Modular<P>& n, const Modular<P>& m) { Modular<P> r = n; return r += m; } friend Modular<P>& operator -= ( Modular<P>& n, const Modular<P>& m) { n.value -= m.value; if (n.value < 0) n.value += P; return n; } friend Modular<P> operator - (const Modular<P>& n, const Modular<P>& m) { Modular<P> r = n; return r -= m; } friend Modular<P> operator - (const Modular<P>& n) { return Modular<P>(-n.value); } friend Modular<P>& operator *= ( Modular<P>& n, const Modular<P>& m) { n.value = n.value * 1ll * m.value % P; return n; } friend Modular<P> operator * (const Modular<P>& n, const Modular<P>& m) { Modular<P> r = n; return r *= m; } friend Modular<P>& operator /= ( Modular<P>& n, const Modular<P>& m) { return n *= m.inv(); } friend Modular<P> operator / (const Modular<P>& n, const Modular<P>& m) { Modular<P> r = n; return r /= m; } Modular<P>& operator ++ ( ) { return *this += 1; } Modular<P>& operator -- ( ) { return *this -= 1; } Modular<P> operator ++ (int) { Modular<P> r = *this; *this += 1; return r; } Modular<P> operator -- (int) { Modular<P> r = *this; *this -= 1; return r; } friend bool operator == (const Modular<P>& n, const Modular<P>& m) { return n.value == m.value; } friend bool operator != (const Modular<P>& n, const Modular<P>& m) { return n.value != m.value; } explicit operator int() const { return value; } explicit operator bool() const { return value; } explicit operator long long() const { return value; } constexpr static value_type mod() { return P; } value_type norm(long long k) { if (!(-P <= k && k < P)) k %= P; if (k < 0) k += P; return k; } Modular<P> inv() const { value_type a = value, b = P, x = 0, y = 1; while (a != 0) { value_type k = b / a; b -= k * a; x -= k * y; swap(a, b); swap(x, y); } return Modular<P>(x); } }; template<auto P> Modular<P> pow(Modular<P> m, long long p) { Modular<P> r(1); while (p) { if (p & 1) r *= m; m *= m; p >>= 1; } return r; } template<auto P> ostream& operator << (ostream& o, const Modular<P>& m) { return o << m.value; } template<auto P> istream& operator >> (istream& i, Modular<P>& m) { long long k; i >> k; m.value = m.norm(k); return i; } template<auto P> string to_string(const Modular<P>& m) { return to_string(m.value); } using Mint = Modular<1000000007>; // using Mint = Modular<998244353>; // using Mint = long double; vector<Mint> f, fi; void init_C(int n) { f.assign(n, 1); fi.assign(n, 1); for (int i = 2; i < n; ++i) f[i] = f[i - 1] * i; fi.back() = Mint(1) / f.back(); for (int i = n - 2; i >= 0; --i) fi[i] = fi[i + 1] * (i + 1); } Mint C(int n, int k) { if (k < 0 || k > n) return 0; else return f[n] * fi[k] * fi[n - k]; } } using namespace mint_ns; array<array<array<Mint, 2>, 10>, 30> dp; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, q; cin >> n >> q; assert(q == 0); string s; cin >> s; for (int i = 0; i < 30; ++i) { for (int j = 0; j < 10; ++j) { for (int k = 0; k < 2; ++k) { dp[i][j][k] = 0; } } } vector<int> v; for (char c : s) v.pb(c - '0'); for (int i = 0; i <= v[0]; ++i) dp[0][i][i == v[0]] = 1; for (int i = 1; i < n; ++i) { for (int prev = 0; prev < 10; ++prev) { for (int next = 0; next < 10; ++next) { if (prev == 1 && next == 3) continue; if (next <= v[i]) { dp[i][next][next == v[i]] += dp[i - 1][prev][1]; } dp[i][next][0] += dp[i - 1][prev][0]; } } } Mint ans = 0; for (int i = 0; i < 10; ++i) for (int j = 0; j < 2; ++j) ans += dp[n - 1][i][j]; cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...