結果
問題 |
No.260 世界のなんとか3
|
ユーザー |
![]() |
提出日時 | 2025-04-15 21:29:37 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,203 bytes |
コンパイル時間 | 232 ms |
コンパイル使用メモリ | 82,036 KB |
実行使用メモリ | 89,336 KB |
最終ジャッジ日時 | 2025-04-15 21:33:04 |
合計ジャッジ時間 | 3,902 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 MLE * 2 |
other | AC * 1 TLE * 5 MLE * 21 |
ソースコード
MOD = 10**9 + 7 def subtract_one(s): s_list = list(s) i = len(s_list) - 1 while i >= 0 and s_list[i] == '0': s_list[i] = '9' i -= 1 if i == -1: return '0' # This case should not occur as per problem constraints s_list[i] = str(int(s_list[i]) - 1) result = ''.join(s_list).lstrip('0') return result if result else '0' def count(x_str): digits = list(map(int, x_str)) n = len(digits) from collections import defaultdict current_dp = defaultdict(int) current_dp[(True, 0, False, 0, False)] = 1 for i in range(n): next_dp = defaultdict(int) for state in current_dp: tight, mod3, has_three, mod8, started = state cnt = current_dp[state] max_d = digits[i] if tight else 9 for d in range(0, max_d + 1): new_tight = tight and (d == max_d) new_started = started or (d != 0) if not started and d == 0: new_mod3 = 0 new_has_three = False new_mod8 = 0 new_started_flag = False else: if not started: new_mod3 = d % 3 new_has_three = (d == 3) new_mod8 = d % 8 new_started_flag = True else: new_mod3 = (mod3 + d) % 3 new_has_three = has_three or (d == 3) new_mod8 = (mod8 * 10 + d) % 8 new_started_flag = True new_state = (new_tight, new_mod3, new_has_three, new_mod8, new_started_flag) next_dp[new_state] = (next_dp[new_state] + cnt) % MOD current_dp = next_dp total = 0 for state in current_dp: tight, mod3, has_three, mod8, started = state if not started: continue aho = (mod3 == 0) or has_three if aho and (mod8 != 0): total = (total + current_dp[state]) % MOD return total A, B = input().split() A_minus_1 = subtract_one(A) result = (count(B) - count(A_minus_1)) % MOD print(result)