結果

問題 No.372 It's automatic
ユーザー te-sh
提出日時 2018-01-10 10:21:50
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2,397 ms / 6,000 ms
コード長 544 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 99,212 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-12 23:27:04
合計ジャッジ時間 29,482 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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, 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