結果

問題 No.9 モンスターのレベル上げ
ユーザー tentententen
提出日時 2020-10-22 16:01:22
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 755 ms / 5,000 ms
コード長 1,553 bytes
コンパイル時間 1,911 ms
使用メモリ 48,640 KB
最終ジャッジ日時 2023-02-20 17:29:51
合計ジャッジ時間 13,007 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 95 ms
40,472 KB
testcase_01 AC 88 ms
38,544 KB
testcase_02 AC 739 ms
48,568 KB
testcase_03 AC 660 ms
46,596 KB
testcase_04 AC 508 ms
48,508 KB
testcase_05 AC 386 ms
47,424 KB
testcase_06 AC 282 ms
45,512 KB
testcase_07 AC 133 ms
40,992 KB
testcase_08 AC 327 ms
45,836 KB
testcase_09 AC 748 ms
46,604 KB
testcase_10 AC 93 ms
40,596 KB
testcase_11 AC 748 ms
45,860 KB
testcase_12 AC 617 ms
45,812 KB
testcase_13 AC 634 ms
47,308 KB
testcase_14 AC 755 ms
48,640 KB
testcase_15 AC 739 ms
46,764 KB
testcase_16 AC 163 ms
42,552 KB
testcase_17 AC 564 ms
48,612 KB
testcase_18 AC 521 ms
46,380 KB
testcase_19 AC 146 ms
39,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] homes = new int[n];
        for (int i = 0; i < n; i++) {
            homes[i] = sc.nextInt();
        }
        int[] enemies = new int[n];
        for (int i = 0; i < n; i++) {
            enemies[i] = sc.nextInt();
        }
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int max = 0;
            PriorityQueue<Monster> queue = new PriorityQueue<>();
            for (int j = 0; j < n; j++) {
                queue.add(new Monster(homes[j]));
            }
            for (int j = 0; j < n; j++) {
                Monster m = queue.poll();
                m.count++;
                max = Math.max(max, m.count);
                m.value += enemies[(i + j) % n] / 2;
                queue.add(m);
            }
            min = Math.min(min, max);
        }
        System.out.println(min);
    }
    
    static class Monster implements Comparable<Monster> {
        int count;
        int value;
        
        public Monster(int value) {
            this.value = value;
        }
        
        public int compareTo(Monster another) {
            if (value == another.value) {
                return count - another.count;
            } else {
                return value - another.value;
            }
        }
        
        public String toString() {
            return "[" + count + ":" + value + "]";
        }
    }
}
0