結果

問題 No.9 モンスターのレベル上げ
ユーザー tentententen
提出日時 2020-10-22 16:01:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 908 ms / 5,000 ms
コード長 1,553 bytes
コンパイル時間 2,410 ms
コンパイル使用メモリ 77,408 KB
実行使用メモリ 61,692 KB
最終ジャッジ日時 2023-09-28 14:37:54
合計ジャッジ時間 14,266 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,940 KB
testcase_01 AC 127 ms
55,692 KB
testcase_02 AC 908 ms
61,364 KB
testcase_03 AC 759 ms
60,652 KB
testcase_04 AC 563 ms
61,124 KB
testcase_05 AC 497 ms
61,216 KB
testcase_06 AC 334 ms
60,380 KB
testcase_07 AC 177 ms
55,752 KB
testcase_08 AC 365 ms
60,692 KB
testcase_09 AC 887 ms
61,028 KB
testcase_10 AC 126 ms
56,036 KB
testcase_11 AC 903 ms
60,968 KB
testcase_12 AC 846 ms
61,364 KB
testcase_13 AC 698 ms
58,904 KB
testcase_14 AC 886 ms
61,132 KB
testcase_15 AC 844 ms
61,216 KB
testcase_16 AC 216 ms
59,020 KB
testcase_17 AC 684 ms
61,692 KB
testcase_18 AC 601 ms
61,160 KB
testcase_19 AC 206 ms
57,764 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