結果

問題 No.372 It's automatic
ユーザー te-shte-sh
提出日時 2017-07-20 15:50:14
言語 D
(dmd 2.106.1)
結果
MLE  
実行時間 -
コード長 601 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 86,704 KB
実行使用メモリ 817,856 KB
最終ジャッジ日時 2023-09-03 15:19:53
合計ジャッジ時間 9,301 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

void main()
{
  auto s = readln.chomp.map!(a => (a - '0').to!int).array, n = s.length;
  auto m = readln.chomp.to!int;

  auto dp = new int[][][](n+1, 2, m);
  dp[0][0][0] = 1;

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

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