結果

問題 No.1085 桁和の桁和
ユーザー nebukuro09nebukuro09
提出日時 2020-06-19 23:21:15
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,059 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 100,972 KB
実行使用メモリ 17,284 KB
最終ジャッジ日時 2023-09-04 08:16:28
合計ジャッジ時間 3,007 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 54 ms
14,696 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 16 ms
6,988 KB
testcase_15 AC 35 ms
13,916 KB
testcase_16 AC 35 ms
14,140 KB
testcase_17 AC 17 ms
7,260 KB
testcase_18 AC 10 ms
6,452 KB
testcase_19 AC 32 ms
13,516 KB
testcase_20 AC 33 ms
11,960 KB
testcase_21 AC 22 ms
8,500 KB
testcase_22 AC 29 ms
12,900 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 19 ms
7,940 KB
testcase_26 AC 36 ms
14,444 KB
testcase_27 AC 30 ms
12,412 KB
testcase_28 AC 40 ms
15,468 KB
testcase_29 AC 24 ms
8,948 KB
testcase_30 AC 21 ms
8,192 KB
testcase_31 AC 36 ms
12,624 KB
testcase_32 AC 25 ms
9,408 KB
testcase_33 AC 55 ms
15,676 KB
testcase_34 AC 56 ms
14,964 KB
testcase_35 AC 55 ms
16,908 KB
testcase_36 AC 56 ms
14,648 KB
testcase_37 AC 56 ms
16,044 KB
testcase_38 AC 57 ms
17,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

immutable long MOD = 10 ^^ 9 + 7;

void main() {
    auto T = readln.chomp;
    auto N = T.length;
    auto D = readln.chomp.to!int;

    auto base = 1;
    foreach (i; 0..T.length.to!int-1) {
        base = base * 10 % 9;
    }

    auto dp = new long[][](N+1, 9);
    dp[0][0] = 1;

    foreach (i; 0..N) {
        foreach (j; 0..9) {
            if (T[i] != '?') {
                (dp[i+1][(j+T[i]-'0')%9] += dp[i][j]) %= MOD;
            } else {
                foreach (k; 0..10) {
                    (dp[i+1][(j+k)%9] += dp[i][j]) %= MOD;
                }
            }
        }
    }

    long zero = 0;
    if (T.map!(a => a == '?' || a =='0').all) {
        zero += 1;
    }

    long ans;

    if (D == 9) {
        ans = dp[N][0] - zero;
    } else if (D == 0) {
        ans = zero;
    } else {
        ans = dp[N][D];
    }

    ans.writeln;
}
0