結果

問題 No.372 It's automatic
ユーザー nebukuro09nebukuro09
提出日時 2017-03-23 09:36:38
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,047 ms / 6,000 ms
コード長 841 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 100,088 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-03 12:34:45
合計ジャッジ時間 14,125 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,388 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1,000 ms
4,384 KB
testcase_05 AC 999 ms
4,384 KB
testcase_06 AC 1,047 ms
4,380 KB
testcase_07 AC 1,012 ms
4,380 KB
testcase_08 AC 1,010 ms
4,380 KB
testcase_09 AC 1,015 ms
4,384 KB
testcase_10 AC 996 ms
4,384 KB
testcase_11 AC 998 ms
4,380 KB
testcase_12 AC 999 ms
4,384 KB
testcase_13 AC 987 ms
4,384 KB
testcase_14 AC 1,025 ms
4,384 KB
testcase_15 AC 1,023 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,388 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 68 ms
4,380 KB
testcase_22 AC 69 ms
4,384 KB
testcase_23 AC 69 ms
4,384 KB
testcase_24 AC 68 ms
4,384 KB
testcase_25 AC 68 ms
4,384 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.string;

immutable int MOD = 10^^9+7;

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

    int[20000][2] dp;
    dp[0][0] = 0;

    foreach (i; 0..N) {
        int cur = i % 2;
        int tar = 1 ^ cur;
        int n = S[i] - '0';
        memcpy(dp[tar].ptr, dp[cur].ptr, dp[cur].sizeof);
        foreach (j; 0..M) {
            dp[tar][(10*j+n)%M] += dp[cur][j];
            dp[tar][(10*j+n)%M] %= MOD;
        }
        if (n != 0) {
            dp[tar][n%M] += 1;
            dp[tar][n%M] %= MOD;
        }
    }

    int ans = S.count('0').to!int + dp[N%2][0];
    ans %= MOD;
    ans.writeln;
}
0