結果

問題 No.1085 桁和の桁和
ユーザー nebukuro09nebukuro09
提出日時 2020-06-19 23:19:32
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 102,936 KB
実行使用メモリ 17,868 KB
最終ジャッジ日時 2023-09-04 08:16:25
合計ジャッジ時間 3,034 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 WA -
testcase_04 AC 42 ms
16,040 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
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 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 27 ms
13,396 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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