結果

問題 No.9 モンスターのレベル上げ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-27 22:07:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 3,384 ms / 5,000 ms
コード長 1,058 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 9,236 KB
最終ジャッジ日時 2023-09-06 04:41:38
合計ジャッジ時間 26,049 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,564 KB
testcase_01 AC 20 ms
8,656 KB
testcase_02 AC 2,299 ms
9,076 KB
testcase_03 AC 1,750 ms
9,012 KB
testcase_04 AC 960 ms
9,052 KB
testcase_05 AC 677 ms
8,944 KB
testcase_06 AC 189 ms
8,744 KB
testcase_07 AC 24 ms
8,708 KB
testcase_08 AC 274 ms
8,756 KB
testcase_09 AC 1,988 ms
9,072 KB
testcase_10 AC 20 ms
8,656 KB
testcase_11 AC 2,858 ms
9,056 KB
testcase_12 AC 3,384 ms
8,896 KB
testcase_13 AC 3,199 ms
9,236 KB
testcase_14 AC 2,065 ms
9,160 KB
testcase_15 AC 2,097 ms
8,968 KB
testcase_16 AC 45 ms
8,724 KB
testcase_17 AC 1,360 ms
9,056 KB
testcase_18 AC 1,120 ms
8,956 KB
testcase_19 AC 43 ms
8,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import array
import collections
import heapq


INF = 10 ** 9
State = collections.namedtuple("State", "level battles index")


def compute_min(n, friend_levels, enemy_levels):
    fs = friend_levels
    es = collections.deque(el // 2 for el in enemy_levels)
    answer = INF
    pq_base = [State(f, 0, i) for i, f in enumerate(fs)]
    heapq.heapify(pq_base)
    for _ in range(n):
        pq = pq_base[:]
        for e in es:
            state = heapq.heappop(pq)
            new_level = state.level + e
            new_battles = state.battles + 1
            if new_battles > answer:
                break
            heapq.heappush(pq, State(new_level, new_battles, state.index))
        else:
            answer = min(answer, max(s.battles for s in pq))
        es.rotate()
    return answer


def main():
    n = int(input())
    friend_levels = array.array("I", map(int, input().split()))
    enemy_levels = map(int, input().split())
    print(compute_min(n, friend_levels, enemy_levels))


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