結果

問題 No.189 SUPER HAPPY DAY
コンテスト
ユーザー te-sh
提出日時 2016-09-15 10:21:40
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 1,254 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 599 ms
コンパイル使用メモリ 102,104 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-05 07:34:04
合計ジャッジ時間 1,138 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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 memo = new int[][](maxK * 9 + 1, maxK + 1);

  int calc(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 (f == 10 && memo[n][k] > 0) return memo[n][k];

    auto r = 0;
    foreach (i; 0..f)
      r = (r + calc(di[1..$], n - i, 10)) % mod;
    if (f != 10)
      r = (r + calc(di[1..$], n - f, di[1])) % mod;
    else
      memo[n][k] = r;
    return 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, di[0]);
    return r;
  }

  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 modMul(int a, int b, int mod)
{
  return ((a.to!long * b.to!long) % mod).to!int;
}
0