結果

問題 No.555 世界史のレポート
ユーザー lloyzlloyz
提出日時 2022-09-15 00:15:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 581 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 86,608 KB
実行使用メモリ 77,596 KB
最終ジャッジ日時 2023-08-21 21:42:24
合計ジャッジ時間 3,079 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,344 KB
testcase_01 AC 77 ms
71,372 KB
testcase_02 AC 77 ms
71,112 KB
testcase_03 AC 78 ms
71,112 KB
testcase_04 AC 78 ms
71,200 KB
testcase_05 AC 79 ms
71,324 KB
testcase_06 AC 78 ms
71,028 KB
testcase_07 AC 77 ms
71,200 KB
testcase_08 AC 77 ms
71,304 KB
testcase_09 AC 77 ms
71,360 KB
testcase_10 AC 81 ms
74,932 KB
testcase_11 AC 81 ms
75,256 KB
testcase_12 AC 84 ms
75,948 KB
testcase_13 AC 84 ms
75,528 KB
testcase_14 AC 113 ms
77,596 KB
testcase_15 AC 82 ms
75,372 KB
testcase_16 AC 81 ms
75,252 KB
testcase_17 AC 80 ms
75,356 KB
testcase_18 AC 80 ms
75,312 KB
testcase_19 AC 82 ms
75,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush

n = int(input())
c, v = map(int, input().split())

H = [(c, 1, 1)]
INF = 10**18
DP = [INF for _ in range(n + 1)]
DP[1] = c
heapify(H)
while H:
    cost, num, c_num = heappop(H)
    if num >= n:
        print(cost)
        break
    if c_num != num:
        if cost + c + v < DP[min(num * 2, n)]:
            DP[min(num * 2, n)] = cost + c + v
            heappush(H, (cost + c + v, num * 2, num))
    if cost + v < DP[min(num + c_num, n)]:
        DP[min(num + c_num, n)] = cost + v
        heappush(H, (cost + v, num + c_num, c_num))
0