結果

問題 No.372 It's automatic
ユーザー te-shte-sh
提出日時 2018-01-10 10:21:50
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2,517 ms / 6,000 ms
コード長 544 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 84,316 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 18:00:38
合計ジャッジ時間 32,602 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2,488 ms
4,376 KB
testcase_05 AC 2,495 ms
4,376 KB
testcase_06 AC 2,475 ms
4,376 KB
testcase_07 AC 2,488 ms
4,376 KB
testcase_08 AC 2,491 ms
4,380 KB
testcase_09 AC 2,485 ms
4,376 KB
testcase_10 AC 2,486 ms
4,380 KB
testcase_11 AC 2,467 ms
4,380 KB
testcase_12 AC 2,488 ms
4,376 KB
testcase_13 AC 2,481 ms
4,376 KB
testcase_14 AC 2,505 ms
4,380 KB
testcase_15 AC 2,517 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 125 ms
4,376 KB
testcase_22 AC 128 ms
4,376 KB
testcase_23 AC 130 ms
4,376 KB
testcase_24 AC 128 ms
4,376 KB
testcase_25 AC 129 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const mod = 10 ^^ 9 + 7;

void main()
{
  auto s = readln.chomp, n = s.length;
  auto m = readln.chomp.to!int;

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

  foreach (c; s) {
    auto d = cast(int)(c-'0');
    foreach (q; 0..2) dp2[q][] = dp1[q][];
    foreach (q; 0..2)
      foreach (r; 0..m)
        if (d > 0 || q == 1)
          (dp2[1][(r * 10 + d) % m] += dp1[q][r]) %= mod;
    swap(dp1, dp2);
  }

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