結果

問題 No.372 It's automatic
ユーザー te-shte-sh
提出日時 2017-07-20 17:00:52
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 3,439 ms / 6,000 ms
コード長 524 bytes
コンパイル時間 1,702 ms
コンパイル使用メモリ 88,940 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-03 15:21:14
合計ジャッジ時間 44,854 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,388 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 3,400 ms
4,384 KB
testcase_05 AC 3,408 ms
4,384 KB
testcase_06 AC 3,395 ms
4,380 KB
testcase_07 AC 3,419 ms
4,384 KB
testcase_08 AC 3,413 ms
4,380 KB
testcase_09 AC 3,407 ms
4,384 KB
testcase_10 AC 3,411 ms
4,388 KB
testcase_11 AC 3,379 ms
4,380 KB
testcase_12 AC 3,438 ms
4,384 KB
testcase_13 AC 3,397 ms
4,380 KB
testcase_14 AC 3,423 ms
4,380 KB
testcase_15 AC 3,439 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 178 ms
4,384 KB
testcase_22 AC 179 ms
4,380 KB
testcase_23 AC 177 ms
4,380 KB
testcase_24 AC 177 ms
4,384 KB
testcase_25 AC 177 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

const mod = 10 ^^ 9 + 7;

void main()
{
  auto s = readln.chomp.map!(a => (a - '0').to!int).array, n = s.length;
  auto m = readln.chomp.to!int;

  auto dp1 = new int[][](2, m);
  dp1[0][0] = 1;

  foreach (p; 0..n) {
    auto dp2 = dp1.map!(a => a.dup).array;
    foreach (q; 0..2)
      foreach (r; 0..m)
        if (s[p] > 0 || q == 1)
          (dp2[1][(r * 10 + s[p]) % m] += dp1[q][r]) %= mod;
    dp1 = dp2;
  }

  writeln(dp1[1][0] + s.count(0));
}
0