結果

問題 No.189 SUPER HAPPY DAY
コンテスト
ユーザー norioc
提出日時 2026-01-05 02:24:43
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 849 ms / 5,000 ms
コード長 1,241 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 351 ms
コンパイル使用メモリ 82,864 KB
実行使用メモリ 94,424 KB
最終ジャッジ日時 2026-01-05 02:24:52
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections.abc import Iterable


def accum_dp(xs: Iterable, f, op, e, init: dict, *, is_reset=True):
    dp = init.copy()
    for x in xs:
        pp = {} if is_reset else dp.copy()
        dp, pp = pp, dp
        for fm_key, fm_val in pp.items():
            for to_key, to_val in f(fm_key, fm_val, x):
                dp[to_key] = op(dp.get(to_key, e), to_val)

    return dp


def f(k, v, ix):
    s, lt = k  # (桁和, 未満か)

    _, digit = ix
    for d in range(10):
        if lt:
            yield (s+d, lt), v
        elif d <= digit:
            nlt = d < digit
            yield (s+d, nlt), v


def op(a, b):
    return (a + b) % MOD


# n 以下の整数の桁和の数え上げ
def digit_dp(n: int) -> dict:
    digits = [int(c) for c in str(n)]

    init = {}
    for d in range(10):
        if d <= digits[0]:
            lt = d < digits[0]
            init[d, lt] = 1

    xs = list(enumerate(digits))
    dp = accum_dp(xs[1:], f, op, 0, init)
    return dp


MOD = 10**9 + 9
M, D = map(int, input().split())

m_dp = digit_dp(M)
d_dp = digit_dp(D)
ans = 0
for (s, _), v in m_dp.items():
    if s == 0: continue
    ans += v * d_dp.get((s, True), 0)
    ans += v * d_dp.get((s, False), 0)
    ans %= MOD

print(ans)
0