結果

問題 No.372 It's automatic
コンテスト
ユーザー norioc
提出日時 2026-01-05 14:28:36
言語 PyPy3
(7.3.17)
結果
TLE  
実行時間 -
コード長 959 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 421 ms
コンパイル使用メモリ 82,680 KB
実行使用メモリ 273,112 KB
最終ジャッジ日時 2026-01-05 14:28:45
合計ジャッジ時間 8,588 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 1 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

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):
    global ans
    b, m = k  # (開始ノードか, mod)

    if b:
        if x > 0:
            if x % M == 0:
                ans += 1
            yield (False, x % M), v
    else:
        nm = (10*m + x) % M
        if nm == 0:
            ans += v
        yield (False, nm), v


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


def digit_dp():
    digits = [int(c) for c in S]

    init = {(True, 0): 1}
    _ = accum_dp(digits, f, op, 0, init, is_reset=False)


MOD = 10**9 + 7
S = input()
M = int(input())

ans = 0
digit_dp()

ans += S.count('0')
print(ans)
0