結果

問題 No.9 モンスターのレベル上げ
ユーザー lam6er
提出日時 2025-03-31 17:20:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,972 ms / 5,000 ms
コード長 1,248 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 141,832 KB
最終ジャッジ日時 2025-03-31 17:22:01
合計ジャッジ時間 40,498 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    A = list(map(int, input[ptr:ptr+N]))
    ptr += N
    B = list(map(int, input[ptr:ptr+N]))
    
    min_max = float('inf')
    
    for k in range(N):
        levels = A.copy()
        counts = [0] * N
        heap = [(levels[i], counts[i], i) for i in range(N)]
        heapq.heapify(heap)
        current_max = 0
        
        for i in range(N):
            enemy_idx = (k + i) % N
            enemy_level = B[enemy_idx]
            
            while True:
                current_lvl, current_cnt, idx = heapq.heappop(heap)
                if current_lvl == levels[idx] and current_cnt == counts[idx]:
                    break
            
            gain = enemy_level // 2
            new_lvl = current_lvl + gain
            new_cnt = current_cnt + 1
            levels[idx] = new_lvl
            counts[idx] = new_cnt
            heapq.heappush(heap, (new_lvl, new_cnt, idx))
            
            if new_cnt > current_max:
                current_max = new_cnt
        
        if current_max < min_max:
            min_max = current_max
    
    print(min_max)

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