Submission #492784

#TimeUsernameProblemLanguageResultExecution timeMemory
492784maksim1744Lucky 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; template<typename T, int N> struct Matrix { array<array<T, N>, N> m; Matrix() { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { m[i][j] = 0; } } } Matrix(std::initializer_list<std::initializer_list<T>> s) { int i = 0; for (auto it = s.begin(); it != s.end(); ++it) { int j = 0; for (auto it2 = it->begin(); it2 != it->end(); ++it2) { m[i][j] = *it2; ++j; } ++i; } } static Matrix E() { Matrix e; for (int i = 0; i < N; ++i) { e[i][i] = 1; } return e; } array<T, N> &operator[](int i) { return m[i]; } const array<T, N> &operator[](int i) const { return m[i]; } Matrix operator * (const Matrix &b) { Matrix c; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { for (int k = 0; k < N; ++k) { c[i][k] += m[i][j] * b[j][k]; } } } return c; } Matrix &operator *= (const Matrix &other) { *this = (*this) * other; return *this; } Matrix &operator *= (const T &x) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { m[i][j] *= x; } } return *this; } Matrix operator * (const T &x) { Matrix a = *this; a *= x; return a; } Matrix &operator /= (const T &x) { T inv = T(1) / x; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { m[i][j] *= inv; } } return *this; } Matrix operator / (const T &x) { Matrix a = *this; a /= x; return a; } Matrix &operator += (const Matrix &other) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { m[i][j] += other[i][j]; } } return *this; } Matrix operator + (const Matrix &other) { Matrix a = *this; a += other; return a; } Matrix &operator -= (const Matrix &other) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { m[i][j] -= other[i][j]; } } return *this; } Matrix operator - (const Matrix &other) { Matrix a = *this; a -= other; return a; } }; template<typename T, int N> Matrix<T, N> pow(Matrix<T, N> m, ll p) { Matrix<T, N> res = Matrix<T, N>::E(); while (p) { if (p & 1) res *= m; m *= m; p >>= 1; } return res; } array<array<Mint, 4>, 30> dp; using M = Matrix<Mint, 4>; array<M, 10> transitions; 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 < dp[i].size(); ++j) { dp[i][j] = 0; } } vector<int> v; for (char c : s) v.pb(c - '0'); auto get_ind = [&](int num, int b) { return (num == 1) + (b) * 2; }; M m = M::E(); for (int i = 0; i < n; ++i) { M cur; for (int prev = 0; prev < 2; ++prev) { for (int next = 0; next < 10; ++next) { if (prev == 1 && next == 3) continue; if (next <= v[i]) { cur[get_ind(next, next == v[i])][get_ind(prev, 1)]++; } cur[get_ind(next, 0)][get_ind(prev, 0)]++; } } m = cur * m; } Mint ans = 0; for (int i = 0; i < 4; ++i) ans += m[i][get_ind(0, 1)]; cout << ans << '\n'; return 0; }

Compilation message (stderr)

lucky.cpp: In function 'int main()':
lucky.cpp:268:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::array<mint_ns::Modular<1000000007>, 4>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  268 |         for (int j = 0; j < dp[i].size(); ++j) {
      |                         ~~^~~~~~~~~~~~~~
#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...