結果

問題 No.1085 桁和の桁和
ユーザー firiexpfiriexp
提出日時 2020-06-19 21:41:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 2,943 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 108,340 KB
実行使用メモリ 21,504 KB
最終ジャッジ日時 2024-11-06 17:31:32
合計ジャッジ時間 3,515 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 75 ms
20,736 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 2 ms
5,248 KB
testcase_12 AC 2 ms
5,248 KB
testcase_13 AC 8 ms
5,460 KB
testcase_14 AC 23 ms
9,984 KB
testcase_15 AC 53 ms
18,816 KB
testcase_16 AC 53 ms
18,560 KB
testcase_17 AC 24 ms
10,496 KB
testcase_18 AC 14 ms
7,168 KB
testcase_19 AC 48 ms
17,024 KB
testcase_20 AC 48 ms
17,152 KB
testcase_21 AC 30 ms
12,160 KB
testcase_22 AC 45 ms
15,872 KB
testcase_23 AC 5 ms
5,248 KB
testcase_24 AC 2 ms
5,248 KB
testcase_25 AC 25 ms
11,136 KB
testcase_26 AC 54 ms
19,200 KB
testcase_27 AC 43 ms
16,000 KB
testcase_28 AC 62 ms
21,376 KB
testcase_29 AC 32 ms
12,928 KB
testcase_30 AC 29 ms
12,032 KB
testcase_31 AC 52 ms
18,560 KB
testcase_32 AC 34 ms
13,696 KB
testcase_33 AC 78 ms
21,504 KB
testcase_34 AC 77 ms
21,376 KB
testcase_35 AC 77 ms
21,376 KB
testcase_36 AC 78 ms
21,504 KB
testcase_37 AC 77 ms
21,376 KB
testcase_38 AC 79 ms
21,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;

int main() {
    int d;
    string s;
    cin >> s >> d;
    int n = s.size();
    auto dp = make_v(n+1, 2, 9, mint(0));
    dp[0][1][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 9; ++k) {
                if(s[i] == '?'){
                    for (int l = 0; l < 10; ++l) {
                        dp[i+1][j&(l == 0)][(k+l)%9] += dp[i][j][k];
                    }
                }else {
                    int l = (s[i]-'0')%10;
                    dp[i+1][j&(l == 0)][(k+l)%9] += dp[i][j][k];
                }
            }
        }
    }
    if(d == 0){
        printf("%d\n", dp.back()[1][0].val);
    }else if(d == 9) {
        printf("%d\n", dp.back()[0][0].val);
    }else {
        printf("%d\n", dp.back()[0][d].val);
    }
    return 0;
}
0