結果

問題 No.3281 Pacific White-sided Dolphin vs Monster
ユーザー hirayuu_yc
提出日時 2025-10-04 10:54:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 4,908 ms
コンパイル使用メモリ 82,160 KB
実行使用メモリ 96,812 KB
最終ジャッジ日時 2025-10-04 10:55:10
合計ジャッジ時間 7,485 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import heapq

def can_finish(H, t):
    # simulate using powers 2^{t-1}, 2^{t-2}, ..., 2^0
    # use a max-heap of remaining healths (store negatives)
    if t == 0:
        return all(h <= 0 for h in H)
    heap = [-h for h in H if h > 0]
    heapq.heapify(heap)
    for k in range(t - 1, -1, -1):
        if not heap:
            return True
        largest = -heapq.heappop(heap)
        largest -= (1 << k)
        if largest > 0:
            heapq.heappush(heap, -largest)
    return not heap  # True if all monsters defeated

def main():
    data = sys.stdin.buffer.read().split()
    if not data:
        return
    it = iter(data)
    n = int(next(it))
    H = [int(next(it)) for _ in range(n)]

    # binary search minimal t in [0, 62]
    lo, hi = 0, 62
    while lo < hi:
        mid = (lo + hi) // 2
        if can_finish(H, mid):
            hi = mid
        else:
            lo = mid + 1
    print(lo)

if __name__ == "__main__":
    main()
0