結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー bayashi-clbayashi-cl
提出日時 2021-11-12 22:45:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,694 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 36,580 KB
最終ジャッジ日時 2024-05-04 10:17:08
合計ジャッジ時間 5,394 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
17,024 KB
testcase_01 AC 41 ms
11,648 KB
testcase_02 AC 39 ms
11,648 KB
testcase_03 AC 241 ms
11,648 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# region template
import sys
import typing
from typing import Callable, Dict, List, Set, Tuple
import heapq
from operator import itemgetter

sys.setrecursionlimit(10 ** 6)
Vec = List[int]
VecVec = List[Vec]
sinput: Callable[..., str] = sys.stdin.readline
MOD: int = 1000000007
INF: float = float("Inf")
IINF: int = sys.maxsize
# endregion


def meguru_bisect(ok: int, ng: int, is_ok: Callable[..., bool], *args) -> int:
    """二分探索法
    Args:
        ok (int): is_okを満たす初期値
        ng (int): is_okを満たさない初期値
        is_ok (typing.Callable[..., bool]): 判定用関数
        *args (object): is_okに渡される引数
    Returns:
        int: is_okを満たす最大/小の整数
    """
    assert is_ok(ok, *args)
    assert not is_ok(ng, *args)

    while abs(ok - ng) > 1:
        mid = (ok + ng) >> 1
        if is_ok(mid, *args):
            ok = mid
        else:
            ng = mid
    return ok


def main() -> None:
    n, a, b, x, y = map(int, sinput().split())
    h = tuple(map(int, sinput().split()))

    def ok(th: int) -> bool:
        if th < 0:
            return False
        rem_b = y * b
        que = [(-h[i] + th, i) for i in range(n)]
        heapq.heapify(que)
        for _ in range(a):
            top, i = heapq.heappop(que)
            top += x
            heapq.heappush(que, (top, i))

        que.sort(key=itemgetter(1))

        for hi, _ in que:
            hi *= -1

            if hi >= 0:
                if hi > rem_b:
                    return False
                else:
                    rem_b -= hi

        return True

    print(meguru_bisect(max(h), -1, ok))


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