結果

問題 No.1085 桁和の桁和
ユーザー kappybarkappybar
提出日時 2020-06-19 22:10:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,251 bytes
コンパイル時間 1,333 ms
コンパイル使用メモリ 170,712 KB
実行使用メモリ 13,612 KB
最終ジャッジ日時 2023-09-30 06:13:26
合計ジャッジ時間 3,055 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 9 ms
6,836 KB
testcase_15 AC 24 ms
11,720 KB
testcase_16 AC 21 ms
11,780 KB
testcase_17 AC 11 ms
7,100 KB
testcase_18 AC 6 ms
5,156 KB
testcase_19 AC 19 ms
10,684 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 13 ms
8,112 KB
testcase_22 AC 18 ms
10,224 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 11 ms
7,500 KB
testcase_26 AC 23 ms
12,104 KB
testcase_27 AC 18 ms
10,152 KB
testcase_28 AC 25 ms
13,308 KB
testcase_29 AC 13 ms
8,416 KB
testcase_30 AC 12 ms
8,060 KB
testcase_31 AC 21 ms
11,876 KB
testcase_32 AC 15 ms
8,824 KB
testcase_33 AC 34 ms
13,360 KB
testcase_34 AC 33 ms
13,364 KB
testcase_35 AC 33 ms
13,516 KB
testcase_36 AC 33 ms
13,612 KB
testcase_37 AC 33 ms
13,420 KB
testcase_38 AC 33 ms
13,300 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();

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

    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;
                 }
            }
        }
    }

    d %= 9;
    cout << dp[n][d] << endl;
    return 0;
}
0