結果
問題 | No.189 SUPER HAPPY DAY |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:18:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 115 ms / 5,000 ms |
コード長 | 2,398 bytes |
コンパイル時間 | 140 ms |
コンパイル使用メモリ | 82,296 KB |
実行使用メモリ | 77,356 KB |
最終ジャッジ日時 | 2025-03-20 21:19:23 |
合計ジャッジ時間 | 2,734 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
MOD = 10**9 + 9def compute_counts(num_str):num = list(map(int, num_str))n = len(num)max_sum = 9 * ncurrent_dp = [[[0] * (max_sum + 1) for _ in range(2)] for __ in range(2)]current_dp[1][1][0] = 1 # Initial state: tight=True, leading_zero=True, sum=0for i in range(n):next_dp = [[[0] * (max_sum + 1) for _ in range(2)] for __ in range(2)]for tight in [0, 1]:for leading_zero in [0, 1]:for current_sum in range(max_sum + 1):count = current_dp[tight][leading_zero][current_sum]if count == 0:continueupper = num[i] if tight else 9for d in range(0, upper + 1):new_tight = tight and (d == upper)new_leading_zero = leading_zero and (d == 0)if new_leading_zero:new_sum = current_sumelse:new_sum = current_sum + dif new_sum > max_sum:continue # Skip if sum exceeds max possiblenext_dp[new_tight][new_leading_zero][new_sum] = (next_dp[new_tight][new_leading_zero][new_sum] + count) % MODcurrent_dp = next_dptotal_counts = [0] * (max_sum + 1)for tight in [0, 1]:for leading_zero in [0, 1]:for s in range(max_sum + 1):cnt = current_dp[tight][leading_zero][s]if leading_zero:total_counts[0] = (total_counts[0] + cnt) % MODelse:if s <= max_sum:total_counts[s] = (total_counts[s] + cnt) % MOD# Subtract 1 from sum 0 (number 0 is invalid)total_counts[0] = (total_counts[0] - 1) % MODcount_dict = {}for s in range(max_sum + 1):if total_counts[s] > 0:count_dict[s] = total_counts[s]return count_dictM, D = input().split()count_m = compute_counts(M)count_d = compute_counts(D)max_possible_s = 9 * 200 # Since M and D can be up to 10^200 digitsresult = 0for s in range(max_possible_s + 1):m = count_m.get(s, 0)d = count_d.get(s, 0)result = (result + m * d) % MODprint(result)