結果

問題 No.1085 桁和の桁和
ユーザー potoooooooopotoooooooo
提出日時 2020-06-19 22:11:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 960 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 198,568 KB
実行使用メモリ 10,708 KB
最終ジャッジ日時 2023-09-30 06:14:00
合計ジャッジ時間 3,895 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 6 ms
7,768 KB
testcase_15 AC 11 ms
9,696 KB
testcase_16 AC 11 ms
9,696 KB
testcase_17 AC 7 ms
7,576 KB
testcase_18 AC 4 ms
4,852 KB
testcase_19 AC 11 ms
9,700 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 7 ms
7,860 KB
testcase_22 AC 10 ms
9,720 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 7 ms
7,624 KB
testcase_26 AC 11 ms
9,664 KB
testcase_27 AC 10 ms
9,628 KB
testcase_28 AC 13 ms
10,568 KB
testcase_29 AC 8 ms
7,620 KB
testcase_30 AC 7 ms
7,560 KB
testcase_31 AC 11 ms
9,656 KB
testcase_32 AC 8 ms
7,624 KB
testcase_33 AC 18 ms
10,704 KB
testcase_34 AC 17 ms
10,540 KB
testcase_35 AC 18 ms
10,540 KB
testcase_36 AC 19 ms
10,704 KB
testcase_37 AC 18 ms
10,540 KB
testcase_38 AC 18 ms
10,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 1000000007;
constexpr int M = 100010;
long long dp[M][9];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string T; cin >> T;
    int D; cin >> D;
    if (D == 0) {
        for (auto &c: T) {
            if (c != '0' && c != '?') {
                cout << 0 << "\n";
                return 0;
            }
        }
        cout << 1 << "\n";
        return 0;
    }
    dp[0][0] = 1;
    int N = T.size();
    for (int i = 0; i < N; i++) {
        if (T[i] != '?') {
            for (int j = 0; j < 9; j++) {
                dp[i+1][(j+T[i]-'0')%9] = dp[i][j]; 
            }
        } else {
            for (int j = 0; j < 9; j++) {
                dp[i][j] %= mod;
                for (int k = 0; k < 10; k++) {
                    dp[i+1][(j+k)%9] += dp[i][j];
                }
            }
        }
    }
    cout << dp[N][D%9] % mod << "\n";
    return 0;
}
0