結果

問題 No.1085 桁和の桁和
ユーザー hedwig100hedwig100
提出日時 2020-06-19 23:14:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 2,495 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 170,188 KB
実行使用メモリ 14,988 KB
最終ジャッジ日時 2023-08-06 14:34:03
合計ジャッジ時間 3,806 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 41 ms
14,272 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 5 ms
4,496 KB
testcase_14 AC 13 ms
7,216 KB
testcase_15 AC 29 ms
13,072 KB
testcase_16 AC 29 ms
13,064 KB
testcase_17 AC 14 ms
7,816 KB
testcase_18 AC 8 ms
5,400 KB
testcase_19 AC 26 ms
12,000 KB
testcase_20 AC 26 ms
12,024 KB
testcase_21 AC 17 ms
8,864 KB
testcase_22 AC 24 ms
11,240 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 15 ms
8,052 KB
testcase_26 AC 30 ms
13,328 KB
testcase_27 AC 25 ms
11,280 KB
testcase_28 AC 34 ms
14,912 KB
testcase_29 AC 18 ms
9,060 KB
testcase_30 AC 16 ms
8,632 KB
testcase_31 AC 29 ms
13,084 KB
testcase_32 AC 20 ms
9,912 KB
testcase_33 AC 43 ms
14,988 KB
testcase_34 AC 43 ms
14,984 KB
testcase_35 AC 43 ms
14,980 KB
testcase_36 AC 43 ms
14,972 KB
testcase_37 AC 44 ms
14,944 KB
testcase_38 AC 44 ms
14,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;


struct Debug {
    template<class T> static void print_value(T value,const char* name) {
        cout << name << ": " << value << '\n';
    }
    template<class T> static void print_vector(vector<T> &vec,const char* name) {
        for (int i = 0;i < vec.size();++i) {
            cout << "  " << name;
            printf("[%d]: ",i);
            cout << vec[i];
        }
        cout << '\n';
    }
    template<class T> static void print_2dvector(vector<vector<T>> &vec,const char* name) {
        for (int i = 0;i < vec.size();++i) {
            for (int j = 0;j < vec[i].size();++j) {
                cout << "  " << name;
                printf("[%d][%d]: ",i,j);
                cout << vec[i][j];
            }
            cout << '\n';
        }
    }
    template<class T> static void print_set(set<T> &st,const char* name) {
        int i = 0;
        for (auto itr = st.begin();itr != st.end(); ++itr,++i) {
            cout << "  " << name;
            printf("[%d]: ",i);
            cout << *itr;
        }
        cout << '\n';
    }

    template<class T1,class T2>
    static void print_map(map<T1,T2> &mp,const char* name) {
        for (auto p: mp) {
            cout << "  " << name << '[' << p.first << ']' << ": " << p.second;
        }
        cout << '\n';
    }
};


int digit_sum(int x,int y) {
    x += y;
    while (x >= 10) {
        x = x/10 + x%10;
    }
    return x;
    cout << x << endl;
}

int main() {
    string T; cin >> T;
    int D; cin >> D;
    int N = T.size();
    //Debug::print_value(N,"N");

    vector<vector<ll>> dp(N + 1,vector<ll>(10,0));
    dp[0][0] = 1;
    rep(i,N) {
        if (T[i] != '?') {
            rep(j,10) {
                int x = digit_sum(j,(int)(T[i] - '0'));
                dp[i + 1][x] += dp[i][j];
                dp[i + 1][x] %= MOD;
            }
        }
        else {
            rep(j,10) {
                rep(k,10) {
                    int x = digit_sum(j,k);
                    dp[i + 1][x] += dp[i][j];
                    dp[i + 1][x] %= MOD;
                }
            }
        }
    }
    ll ans = dp[N][D];
    cout << ans << endl;
    return 0;
}
0