結果

問題 No.9 モンスターのレベル上げ
ユーザー はむ吉🐹
提出日時 2016-05-27 20:47:37
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,149 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-09-26 02:59:22
合計ジャッジ時間 34,105 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import array
import collections
import copy
import heapq


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


def rotations(iterable, tuplify=True):
    d = collections.deque(iterable)
    n = len(d)
    for _ in range(n):
        d.rotate()
        y = copy.copy(d)
        yield tuple(y) if tuplify else y


def compute_min(friend_levels, enemy_levels):
    fs = friend_levels
    answer = INF
    for es in rotations(enemy_levels, False):
        pq = [State(f, 0, i) for i, f in enumerate(fs)]
        heapq.heapify(pq)
        while es:
            state = heapq.heappop(pq)
            e = es.popleft()
            new_level = state.level + e // 2
            new_battles = state.battles + 1
            heapq.heappush(pq, State(new_level, new_battles, state.index))
        answer = min(answer, max(s.battles for s in pq))
    return answer


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


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