結果

問題 No.372 It's automatic
ユーザー ikdikd
提出日時 2018-10-05 08:08:12
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,614 ms / 6,000 ms
コード長 770 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 85,684 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-03 21:08:47
合計ジャッジ時間 21,407 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1,595 ms
4,380 KB
testcase_05 AC 1,605 ms
4,380 KB
testcase_06 AC 1,598 ms
4,376 KB
testcase_07 AC 1,603 ms
4,380 KB
testcase_08 AC 1,606 ms
4,500 KB
testcase_09 AC 1,603 ms
4,380 KB
testcase_10 AC 1,601 ms
4,376 KB
testcase_11 AC 1,594 ms
4,376 KB
testcase_12 AC 1,614 ms
4,376 KB
testcase_13 AC 1,587 ms
4,380 KB
testcase_14 AC 1,603 ms
4,376 KB
testcase_15 AC 1,607 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 86 ms
4,376 KB
testcase_22 AC 85 ms
4,376 KB
testcase_23 AC 85 ms
4,376 KB
testcase_24 AC 86 ms
4,376 KB
testcase_25 AC 86 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  auto s = readln.chomp.to!(char[]);
  int m;
  rd(m);
  const int mod = 10 ^^ 9 + 7;

  int zero = 0;
  auto dp = new int[](m);
  foreach (i; 0 .. s.length) {
    auto nex = new int[](m);
    auto d = s[i] - '0';
    foreach (j; 0 .. m) {
      (nex[j] += dp[j]) %= mod;
      (nex[(j * 10 + d) % m] += dp[j]) %= mod;
    }
    if (d == 0) {
      (zero += 1) %= mod;
    } else {
      (nex[d % m] += 1) %= mod;
    }
    dp.swap(nex);
  }
  writeln((dp[0] + zero) % mod);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}
0