結果

問題 No.189 SUPER HAPPY DAY
ユーザー ikdikd
提出日時 2018-10-05 04:42:05
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 97 ms / 5,000 ms
コード長 1,197 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 84,092 KB
実行使用メモリ 15,532 KB
最終ジャッジ日時 2023-09-03 21:04:26
合計ジャッジ時間 2,805 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,388 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 35 ms
6,796 KB
testcase_14 AC 50 ms
9,008 KB
testcase_15 AC 55 ms
9,004 KB
testcase_16 AC 64 ms
9,708 KB
testcase_17 AC 67 ms
10,592 KB
testcase_18 AC 52 ms
9,252 KB
testcase_19 AC 72 ms
12,048 KB
testcase_20 AC 19 ms
5,040 KB
testcase_21 AC 17 ms
4,384 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 49 ms
9,260 KB
testcase_24 AC 49 ms
9,220 KB
testcase_25 AC 97 ms
15,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

  auto args = readln.split.to!(string[]);
  const long mod = 10 ^^ 9 + 9;
  long[][] solve(string n) {
    auto dp = new long[][][](n.length + 1, 2, n.length * 10);
    dp[0][0][0] = 1;
    foreach (i; 0 .. n.length) {
      foreach (l; 0 .. 2) {
        foreach (s; 0 .. (n.length * 10)) {
          auto d = l ? 9 : n[i] - '0';
          for (int digit = 0; digit <= d; digit++) {
            auto less = l || (digit < d);
            auto sum = s + digit;
            if (sum < n.length * 10) {
              (dp[i + 1][less][sum] += dp[i][l][s]) %= mod;
            }
          }
        }
      }
    }
    return dp[n.length];
  }

  auto dp1 = solve(args[0]), dp2 = solve(args[1]);
  long tot = 0;
  foreach (i; 0 .. 2) {
    foreach (j; 0 .. 2) {
      foreach (s; 1 .. min(dp1[i].length, dp2[j].length)) {
        (tot += dp1[i][s] * dp2[j][s] % mod) %= mod;
      }
    }
  }
  writeln(tot);
}

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