結果
| 問題 | No.1407 Kindness |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-01-30 00:36:06 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 419 ms / 2,000 ms |
| コード長 | 1,020 bytes |
| 記録 | |
| コンパイル時間 | 2,115 ms |
| コンパイル使用メモリ | 82,324 KB |
| 実行使用メモリ | 77,832 KB |
| 最終ジャッジ日時 | 2026-01-30 00:36:17 |
| 合計ジャッジ時間 | 9,068 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
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 op(a, b):
return (a + b) % MOD
def f(k, v, x):
lz, lt = k # (leading zero, 未満か)
for d in range(10):
if not lt and d > x: break
nlz = lz and d == 0
nlt = lt or d < x
if nlz:
yield (nlz, nlt), 1
elif d > 0:
yield (nlz, nlt), v * d
def digit_dp() -> int:
digits = [int(c) for c in N]
init = {(True, False): 1}
dp = accum_dp(digits, f, op, 0, init)
res = 0
for (lz, _), v in dp.items():
if not lz:
res += v
res %= MOD
return res
MOD = 10**9 + 7
N = input()
ans = digit_dp()
print(ans)
norioc