結果
| 問題 | No.372 It's automatic |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-01-05 12:02:47 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 971 bytes |
| 記録 | |
| コンパイル時間 | 370 ms |
| コンパイル使用メモリ | 82,572 KB |
| 実行使用メモリ | 272,964 KB |
| 最終ジャッジ日時 | 2026-01-05 12:02:56 |
| 合計ジャッジ時間 | 8,495 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 1 TLE * 1 -- * 21 |
ソースコード
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 x == 0:
ans += 1
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()
print(ans)
norioc