結果

問題 No.9 モンスターのレベル上げ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-27 20:47:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,149 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2023-11-12 02:41:04
合計ジャッジ時間 52,752 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,496 KB
testcase_01 AC 32 ms
10,496 KB
testcase_02 TLE -
testcase_03 AC 4,049 ms
10,880 KB
testcase_04 AC 2,207 ms
10,752 KB
testcase_05 AC 1,495 ms
10,752 KB
testcase_06 AC 520 ms
10,624 KB
testcase_07 AC 42 ms
10,496 KB
testcase_08 AC 687 ms
10,624 KB
testcase_09 TLE -
testcase_10 AC 32 ms
10,496 KB
testcase_11 AC 4,918 ms
11,008 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 AC 4,652 ms
11,008 KB
testcase_16 AC 113 ms
10,496 KB
testcase_17 AC 2,984 ms
10,880 KB
testcase_18 AC 2,528 ms
10,752 KB
testcase_19 AC 80 ms
10,496 KB
権限があれば一括ダウンロードができます

ソースコード

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