結果

問題 No.555 世界史のレポート
ユーザー lloyzlloyz
提出日時 2022-09-15 00:10:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 629 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 77,948 KB
最終ジャッジ日時 2023-08-21 21:38:07
合計ジャッジ時間 3,045 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,380 KB
testcase_01 AC 73 ms
71,080 KB
testcase_02 AC 77 ms
71,108 KB
testcase_03 AC 77 ms
71,404 KB
testcase_04 AC 76 ms
71,228 KB
testcase_05 AC 75 ms
71,324 KB
testcase_06 AC 76 ms
71,208 KB
testcase_07 AC 76 ms
71,336 KB
testcase_08 AC 74 ms
71,408 KB
testcase_09 AC 74 ms
71,308 KB
testcase_10 AC 78 ms
75,648 KB
testcase_11 AC 77 ms
75,368 KB
testcase_12 AC 82 ms
75,932 KB
testcase_13 AC 83 ms
76,196 KB
testcase_14 WA -
testcase_15 AC 78 ms
75,524 KB
testcase_16 AC 76 ms
75,380 KB
testcase_17 AC 78 ms
75,408 KB
testcase_18 AC 77 ms
75,304 KB
testcase_19 AC 80 ms
75,552 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 cost > DP[min(num, n)]:
        continue
    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