結果

問題 No.9 モンスターのレベル上げ
ユーザー htensaihtensai
提出日時 2020-01-15 10:07:05
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 777 ms / 5,000 ms
コード長 1,877 bytes
コンパイル時間 1,875 ms
使用メモリ 53,744 KB
最終ジャッジ日時 2023-01-16 19:46:49
合計ジャッジ時間 11,879 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 94 ms
45,972 KB
testcase_01 AC 95 ms
42,864 KB
testcase_02 AC 726 ms
51,372 KB
testcase_03 AC 507 ms
50,256 KB
testcase_04 AC 477 ms
53,744 KB
testcase_05 AC 440 ms
52,068 KB
testcase_06 AC 302 ms
52,244 KB
testcase_07 AC 118 ms
44,320 KB
testcase_08 AC 311 ms
49,504 KB
testcase_09 AC 716 ms
51,816 KB
testcase_10 AC 96 ms
43,140 KB
testcase_11 AC 777 ms
53,404 KB
testcase_12 AC 660 ms
51,376 KB
testcase_13 AC 597 ms
51,576 KB
testcase_14 AC 646 ms
51,992 KB
testcase_15 AC 671 ms
51,364 KB
testcase_16 AC 179 ms
45,780 KB
testcase_17 AC 577 ms
51,844 KB
testcase_18 AC 480 ms
53,292 KB
testcase_19 AC 160 ms
47,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;

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