結果

問題 No.372 It's automatic
ユーザー te-sh
提出日時 2017-08-10 10:26:47
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 3,519 ms / 6,000 ms
コード長 537 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 100,440 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-12 21:24:40
合計ジャッジ時間 44,169 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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), dp2 = new int[][](2, m);
  dp1[0][0] = 1;

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

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