結果

問題 No.555 世界史のレポート
ユーザー lloyzlloyz
提出日時 2022-09-15 00:15:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 581 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 8,624 KB
最終ジャッジ日時 2023-08-21 21:42:27
合計ジャッジ時間 1,473 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,100 KB
testcase_01 AC 16 ms
7,936 KB
testcase_02 AC 16 ms
7,988 KB
testcase_03 AC 16 ms
8,032 KB
testcase_04 AC 16 ms
7,952 KB
testcase_05 AC 16 ms
8,048 KB
testcase_06 AC 16 ms
8,060 KB
testcase_07 AC 16 ms
7,944 KB
testcase_08 AC 16 ms
7,976 KB
testcase_09 AC 16 ms
7,944 KB
testcase_10 AC 18 ms
8,612 KB
testcase_11 AC 18 ms
8,448 KB
testcase_12 AC 19 ms
8,488 KB
testcase_13 AC 18 ms
8,552 KB
testcase_14 AC 22 ms
8,492 KB
testcase_15 AC 18 ms
8,552 KB
testcase_16 AC 18 ms
8,424 KB
testcase_17 AC 18 ms
8,496 KB
testcase_18 AC 19 ms
8,472 KB
testcase_19 AC 19 ms
8,624 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