結果

問題 No.555 世界史のレポート
ユーザー ntuda
提出日時 2025-01-29 22:13:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 491 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 74,312 KB
最終ジャッジ日時 2025-01-29 22:13:03
合計ジャッジ時間 2,227 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

N = int(input())
C, V = map(int, input().split())
INF = 10 ** 8
D = [INF] * (N + 1)
D[1] = 0
Q = [(C + V, 2, 1)]
D[2] = C + V
while Q:
    cost, i, cb = heappop(Q)
    if D[min(N, i + cb)] > cost + V:
        D[min(N, i + cb)] = cost + V
        if N > i + cb:
            heappush(Q, (D[i + cb], i + cb, cb))
    if D[min(N, 2 * i)] > cost + C + V:
        D[min(N, 2 * i)] = cost + C + V
        if N > 2 * i:
            heappush(Q, (D[2 * i], 2 * i, i))
print(D[N])
0