結果

問題 No.2416 vs Slime
ユーザー lam6er
提出日時 2025-03-20 20:20:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 54,440 KB
最終ジャッジ日時 2025-03-20 20:22:29
合計ジャッジ時間 3,020 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

H, A = map(int, input().split())

count = {}
count[H] = 1

heap = []
heapq.heappush(heap, -H)  # Using max heap by negating values

ans = 0

while heap:
    current_h = -heapq.heappop(heap)
    if current_h not in count or count[current_h] == 0:
        continue
    c = count[current_h]
    ans += c
    h_new = current_h // A
    if h_new > 0:
        if h_new in count:
            count[h_new] += 2 * c
        else:
            count[h_new] = 2 * c
        heapq.heappush(heap, -h_new)
    count[current_h] = 0  # Mark as processed

print(ans)
0