結果

問題 No.1085 桁和の桁和
ユーザー kappybarkappybar
提出日時 2020-06-19 22:29:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,449 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 171,252 KB
実行使用メモリ 13,392 KB
最終ジャッジ日時 2023-08-06 14:32:48
合計ジャッジ時間 3,504 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 12 ms
6,760 KB
testcase_15 AC 26 ms
11,808 KB
testcase_16 AC 25 ms
11,800 KB
testcase_17 AC 12 ms
6,944 KB
testcase_18 AC 7 ms
5,172 KB
testcase_19 AC 23 ms
10,756 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 15 ms
8,116 KB
testcase_22 AC 22 ms
10,116 KB
testcase_23 AC 4 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 14 ms
7,560 KB
testcase_26 AC 27 ms
12,056 KB
testcase_27 AC 22 ms
10,160 KB
testcase_28 AC 30 ms
13,332 KB
testcase_29 AC 16 ms
8,376 KB
testcase_30 AC 14 ms
8,044 KB
testcase_31 AC 26 ms
11,704 KB
testcase_32 AC 17 ms
8,804 KB
testcase_33 AC 39 ms
13,392 KB
testcase_34 AC 39 ms
13,292 KB
testcase_35 AC 40 ms
13,288 KB
testcase_36 AC 40 ms
13,280 KB
testcase_37 AC 40 ms
13,344 KB
testcase_38 AC 40 ms
13,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    string t;
    cin >> t;
    int d;
    cin >> d;
    int n = t.size();

    bool zero = true;
    if(d==0){
        rep(i,n){
            if('1' <= t[i] && t[i] <= '9') zero = false;
        }
        if(zero) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }

    rep(i,n){
            if('1' <= t[i] && t[i] <= '9') zero = false;
    }

    vector<vector<ll>> dp(n+1,vector<ll>(9,0));
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        bool q = false;
        int td = t[i] - '0';
        if(td < 0 || 9 < td) q = true;
        if(!q){
            for(int j=0;j<9;j++){
                dp[i+1][(10*j+td)%9] += dp[i][j];
                dp[i+1][(10*j+td)%9] %= MOD;
            }
        }else{
             for(int j=0;j<9;j++){
                 rep(k,10){
                    dp[i+1][(10*j+k)%9] += dp[i][j];
                    dp[i+1][(10*j+k)%9] %= MOD;
                 }
            }
        }
    }

    if(d==9){
        ll ans = dp[n][0];
        if(zero) cout << ans-1 << endl;
        else cout << ans << endl;
    }else{
        cout << dp[n][d] << endl;
    }
    return 0;
}
0