結果

問題 No.1085 桁和の桁和
ユーザー ShibuyapShibuyap
提出日時 2020-06-26 23:34:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,201 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 198,664 KB
実行使用メモリ 10,448 KB
最終ジャッジ日時 2023-09-30 06:32:36
合計ジャッジ時間 3,309 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 23 ms
10,204 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 6 ms
4,724 KB
testcase_15 AC 13 ms
6,544 KB
testcase_16 AC 13 ms
6,452 KB
testcase_17 AC 7 ms
4,900 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 12 ms
6,152 KB
testcase_20 AC 11 ms
6,272 KB
testcase_21 AC 8 ms
5,168 KB
testcase_22 AC 11 ms
5,984 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 8 ms
4,964 KB
testcase_26 AC 12 ms
6,672 KB
testcase_27 AC 11 ms
5,976 KB
testcase_28 AC 13 ms
7,008 KB
testcase_29 AC 8 ms
5,496 KB
testcase_30 AC 7 ms
5,176 KB
testcase_31 AC 12 ms
6,712 KB
testcase_32 AC 8 ms
5,516 KB
testcase_33 AC 22 ms
10,428 KB
testcase_34 AC 24 ms
10,392 KB
testcase_35 AC 21 ms
10,400 KB
testcase_36 AC 24 ms
10,432 KB
testcase_37 AC 25 ms
10,404 KB
testcase_38 AC 25 ms
10,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 1000000
int dp[MAX_N] = {};
int main() {
    string t;
    cin >> t;
    int d;
    cin >> d;
    int n = 0;
    int sum = 0;
    rep(i,t.size()){
        if(t[i] == '?')n++;
        else sum += t[i] - '0';
    }

    ll dp[n][9];
    rep(i,n)rep(j,9)dp[i][j] = 0;
    ll MOD = 1e9+7;
    rep(i,n){
        if(i == 0){
            rep(j,9)dp[i][j] = 1;
            dp[i][0] = 2;
        }else{
            rep(j,9){
                rep(k,10){
                    dp[i][(j+k)%9] += dp[i-1][j];
                }
            }
            rep(j,9)dp[i][j] %= MOD;
        }
    }
    if(sum == 0){
        dp[n-1][0] += MOD - 1;
    }
    int ans = 0;
    if(d == 0){
        if(sum == 0){
            ans = 1;
        }
        cout << ans << endl;
        return 0;
    }
    sum %= 9;
    d = d + 9 - sum;
    d %= 9;

    ans = dp[n-1][d];
    ans %= MOD;
    cout << ans << endl;
    return 0;
}
 
 
0