結果

問題 No.189 SUPER HAPPY DAY
ユーザー ikdikd
提出日時 2018-10-05 04:39:45
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 1,273 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 15,508 KB
最終ジャッジ日時 2023-09-03 21:04:02
合計ジャッジ時間 3,627 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 39 ms
6,868 KB
testcase_14 AC 57 ms
8,224 KB
testcase_15 AC 57 ms
9,032 KB
testcase_16 AC 67 ms
9,480 KB
testcase_17 AC 71 ms
10,012 KB
testcase_18 AC 55 ms
8,296 KB
testcase_19 AC 83 ms
11,004 KB
testcase_20 AC 20 ms
5,084 KB
testcase_21 AC 20 ms
5,620 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 50 ms
9,264 KB
testcase_24 AC 50 ms
10,064 KB
testcase_25 AC 118 ms
15,508 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 (s; 1 .. (dp1[i].length)) {
      foreach (j; 0 .. 2) {
        foreach (t; 1 .. (dp2[j].length)) {
          if (s == t) {
            (tot += dp1[i][s] * dp2[j][t] % 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