結果

問題 No.372 It's automatic
ユーザー te-shte-sh
提出日時 2017-08-10 10:26:47
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 3,085 ms / 6,000 ms
コード長 537 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 86,496 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-09-03 15:43:16
合計ジャッジ時間 39,505 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 3,058 ms
4,376 KB
testcase_05 AC 3,072 ms
4,376 KB
testcase_06 AC 3,055 ms
4,376 KB
testcase_07 AC 3,070 ms
4,380 KB
testcase_08 AC 3,069 ms
4,376 KB
testcase_09 AC 3,064 ms
4,376 KB
testcase_10 AC 3,072 ms
4,380 KB
testcase_11 AC 3,045 ms
4,380 KB
testcase_12 AC 3,077 ms
4,376 KB
testcase_13 AC 3,050 ms
4,564 KB
testcase_14 AC 3,076 ms
4,380 KB
testcase_15 AC 3,085 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 153 ms
4,380 KB
testcase_22 AC 154 ms
4,380 KB
testcase_23 AC 154 ms
4,380 KB
testcase_24 AC 154 ms
4,380 KB
testcase_25 AC 153 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), 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