結果

問題 No.189 SUPER HAPPY DAY
ユーザー lam6er
提出日時 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
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

MOD = 10**9 + 9
def compute_counts(num_str):
num = list(map(int, num_str))
n = len(num)
max_sum = 9 * n
current_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=0
for 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:
continue
upper = num[i] if tight else 9
for 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_sum
else:
new_sum = current_sum + d
if new_sum > max_sum:
continue # Skip if sum exceeds max possible
next_dp[new_tight][new_leading_zero][new_sum] = (
next_dp[new_tight][new_leading_zero][new_sum] + count
) % MOD
current_dp = next_dp
total_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) % MOD
else:
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) % MOD
count_dict = {}
for s in range(max_sum + 1):
if total_counts[s] > 0:
count_dict[s] = total_counts[s]
return count_dict
M, 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 digits
result = 0
for s in range(max_possible_s + 1):
m = count_m.get(s, 0)
d = count_d.get(s, 0)
result = (result + m * d) % MOD
print(result)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0