結果
問題 |
No.3045 反復重み付き累積和
|
ユーザー |
![]() |
提出日時 | 2025-06-12 20:29:16 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,205 bytes |
コンパイル時間 | 161 ms |
コンパイル使用メモリ | 81,788 KB |
実行使用メモリ | 53,996 KB |
最終ジャッジ日時 | 2025-06-12 20:29:37 |
合計ジャッジ時間 | 3,242 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 41 |
ソースコード
def main(): import sys sys.setrecursionlimit(1 << 25) N, M = map(int, sys.stdin.readline().split()) if M >= 9: print(0) return s = str(N) len_n = len(s) memo = {} def dp(pos, tight, max_so_far, leading_zero): if pos == len_n: return 1 key = (pos, tight, max_so_far, leading_zero) if key in memo: return memo[key] limit = int(s[pos]) if tight else 9 total = 0 for d in range(0, limit + 1): new_tight = tight and (d == limit) if leading_zero: if d == 0: new_leading_zero = True new_max = max_so_far else: new_leading_zero = False new_max = d else: new_leading_zero = False new_max = max(max_so_far, d) if not leading_zero and new_max > M: continue total += dp(pos + 1, new_tight, new_max, new_leading_zero) memo[key] = total return total x = dp(0, True, -1, True) answer = (N + 1) - x print(answer) if __name__ == "__main__": main()