結果

問題 No.189 SUPER HAPPY DAY
ユーザー te-shte-sh
提出日時 2016-09-14 20:39:02
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,304 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 107,740 KB
実行使用メモリ 80,124 KB
最終ジャッジ日時 2023-09-02 22:09:43
合計ジャッジ時間 7,749 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 10 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 6 ms
4,368 KB
testcase_04 AC 6 ms
4,368 KB
testcase_05 AC 7 ms
4,368 KB
testcase_06 AC 6 ms
4,372 KB
testcase_07 AC 7 ms
4,372 KB
testcase_08 AC 6 ms
4,368 KB
testcase_09 AC 7 ms
4,372 KB
testcase_10 AC 7 ms
4,372 KB
testcase_11 AC 7 ms
4,368 KB
testcase_12 AC 7 ms
4,368 KB
testcase_13 TLE -
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.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

const auto mod = 10 ^^ 9 + 9;

void main()
{
  auto rd = readln.split.map!(a => a.map!(c => c - '0').map!(to!int).array);
  auto m = rd[0], d = rd[1];

  auto maxK = max(m.length, d.length);

  auto mr = sum(m), dr = sum(d);

  auto r = 0;
  foreach (i; 0..min(mr.length, dr.length))
    r = (r + modMul(mr[i], dr[i], mod)) % mod;

  writeln(r);
}

int[] sum(int[] di) {
  auto r = new int[](di.length * 9 + 1);
  foreach (n; 1..di.length * 9 + 1)
    r[n] = calc(di, n.to!int);
  return r;
}

int calc(int[] di, int n)
{
  auto k = di.length.to!int;
  auto memo = new int[][][](k * 9 + 1, k + 1, 11);

  int dp(int[] di, int n, int f) {
    auto k = di.length;
    if (n < 0 || k * 9 < n) return 0;
    if (k == 1) return f < n ? 0 : 1;
    if (memo[n][k][f] > 0) return memo[n][k][f];

    auto r = 0;
    foreach (i; 0..f)
      r = (r + dp(di[1..$], n - i, 10)) % mod;
    if (f != 10)
      r = (r + dp(di[1..$], n - f, di[1])) % mod;
    memo[n][k][f] = r;
    return r;
  }

  return dp(di, n, di[0]);
}

int modMul(int a, int b, int mod)
{
  return ((a.to!long * b.to!long) % mod).to!int;
}
0