Submission #3949534


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/











string K; int D, N;
mint dp[10101][101][2];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> K >> D;
    int N = K.length();

    dp[0][0][0] = 1;
    rep(dgt, 0, N) rep(d, 0, D) rep(isless, 0, 2) {
        int c = K[dgt] - '0';
        rep(nxt, 0, 10) {
            if (nxt < c) dp[dgt + 1][(d + nxt) % D][1] += dp[dgt][d][isless];
            else if(nxt == c) dp[dgt + 1][(d + nxt) % D][isless] += dp[dgt][d][isless];
            else {
                if(isless) dp[dgt + 1][(d + nxt) % D][isless] += dp[dgt][d][isless];
            }
        }
    }

    cout << dp[N][0][0] + dp[N][0][1] - 1 << endl;
}

Submission Info

Submission Time
Task S - Digit Sum
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 3642 Byte
Status AC
Exec Time 134 ms
Memory 8192 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 25
Set Name Test Cases
All 0_00, 0_01, 0_02, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17, 1_18, 1_19, 1_20, 1_21
Case Name Status Exec Time Memory
0_00 AC 4 ms 8192 KB
0_01 AC 4 ms 8192 KB
0_02 AC 5 ms 8192 KB
1_00 AC 4 ms 8192 KB
1_01 AC 4 ms 8192 KB
1_02 AC 5 ms 8192 KB
1_03 AC 127 ms 8192 KB
1_04 AC 129 ms 8192 KB
1_05 AC 112 ms 8192 KB
1_06 AC 120 ms 8192 KB
1_07 AC 112 ms 8192 KB
1_08 AC 134 ms 8192 KB
1_09 AC 133 ms 8192 KB
1_10 AC 131 ms 8192 KB
1_11 AC 122 ms 8192 KB
1_12 AC 118 ms 8192 KB
1_13 AC 132 ms 8192 KB
1_14 AC 134 ms 8192 KB
1_15 AC 132 ms 8192 KB
1_16 AC 124 ms 8192 KB
1_17 AC 132 ms 8192 KB
1_18 AC 108 ms 8192 KB
1_19 AC 115 ms 8192 KB
1_20 AC 4 ms 8192 KB
1_21 AC 4 ms 8192 KB