結果

問題 No.1085 桁和の桁和
ユーザー potoooooooopotoooooooo
提出日時 2020-06-19 22:13:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 3,401 ms
コンパイル使用メモリ 195,336 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-24 10:03:04
合計ジャッジ時間 3,147 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 6 ms
6,272 KB
testcase_15 AC 12 ms
9,600 KB
testcase_16 AC 12 ms
9,728 KB
testcase_17 AC 7 ms
6,400 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 11 ms
8,960 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 8 ms
7,040 KB
testcase_22 AC 11 ms
8,704 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 7 ms
6,656 KB
testcase_26 AC 13 ms
9,856 KB
testcase_27 AC 11 ms
8,704 KB
testcase_28 AC 15 ms
10,752 KB
testcase_29 AC 9 ms
7,296 KB
testcase_30 AC 8 ms
7,040 KB
testcase_31 AC 13 ms
9,728 KB
testcase_32 AC 9 ms
7,680 KB
testcase_33 AC 19 ms
10,752 KB
testcase_34 AC 19 ms
10,752 KB
testcase_35 AC 20 ms
10,880 KB
testcase_36 AC 20 ms
10,752 KB
testcase_37 AC 20 ms
10,880 KB
testcase_38 AC 19 ms
10,880 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;
    bool zero = true;
    for (auto &c: T) {
        if (c != '0' && c != '?') {
            zero = false;
        }
    }
    if (D == 0) {
        cout << zero << "\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];
                }
            }
        }
    }
    if (zero) dp[N][0]--;
    cout << dp[N][D%9] % mod << "\n";
    return 0;
}
0