結果

問題 No.68 よくある棒を切る問題 (2)
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-22 19:18:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,419 ms / 5,000 ms
コード長 561 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 46,576 KB
最終ジャッジ日時 2023-09-22 21:17:43
合計ジャッジ時間 22,576 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,405 ms
46,380 KB
testcase_01 AC 1,419 ms
46,492 KB
testcase_02 AC 1,417 ms
46,416 KB
testcase_03 AC 1,176 ms
46,576 KB
testcase_04 AC 1,231 ms
46,512 KB
testcase_05 AC 1,221 ms
46,524 KB
testcase_06 AC 1,312 ms
43,928 KB
testcase_07 AC 1,354 ms
45,704 KB
testcase_08 AC 1,161 ms
44,092 KB
testcase_09 AC 1,204 ms
44,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

def read_data():
    N = int(input())
    Ls = list(map(int, input().split()))
    Q = int(input())
    Ks = list(map(int, input().split()))
    return N, Ls, Q, Ks

def solve(N, Ls, Q, Ks):
    Kmax = max(Ks)
    ws = [0] * (Kmax + 1)
    Ls.sort(reverse=True)
    hq = [(-L, 1, L) for L in Ls]
    for k in range(1, Kmax + 1):
        w, n, L = hq[0]
        ws[k] = - w
        heapq.heapreplace(hq, (- L / (n + 1), n + 1, L))
    return [ws[k] for k in Ks]

N, Ls, Q, Ks = read_data()
result = solve(N, Ls, Q, Ks)
for w in result:
    print(w)
0