結果

問題 No.2772 Appearing Even Times
コンテスト
ユーザー norioc
提出日時 2026-01-05 20:11:18
言語 PyPy3
(7.3.17)
結果
TLE  
実行時間 -
コード長 1,352 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 376 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 175,292 KB
最終ジャッジ日時 2026-01-05 20:11:25
合計ジャッジ時間 7,123 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

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, x):
    lz, parity, lt = k  # (leading zero, 各数字の偶奇, 未満か)

    if lz:
        for d in range(1, 10):
            nparity = 1 << d
            yield (False, nparity, True), 1

        yield (True, 0, True), 1  # leading zero 維持
    else:
        for d in range(10):
            if not lt and d > x: break
            nparity = parity ^ (1 << d)
            nlt = lt | (d < x)
            yield (False, nparity, nlt), v


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


def digit_dp() -> int:
    digits = [int(c) for c in N]
    init = {(True, 0, True): 1}
    for d in range(1, digits[0]+1):
        lz = False
        parity = 1 << d
        lt = d < digits[0]
        init[lz, parity, lt] = 1

    dp = accum_dp(digits[1:], f, op, 0, init)
    res = 0
    for (lz, m, _), v in dp.items():
        if not lz and m == 0:
            res += v
            res %= MOD

    return res


MOD = 998244353
N = input()
ans = digit_dp()
print(ans)
0