結果

問題 No.9 モンスターのレベル上げ
ユーザー htensaihtensai
提出日時 2020-01-15 10:07:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 876 ms / 5,000 ms
コード長 1,877 bytes
コンパイル時間 3,776 ms
コンパイル使用メモリ 74,752 KB
実行使用メモリ 61,724 KB
最終ジャッジ日時 2023-08-30 02:39:02
合計ジャッジ時間 14,465 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,992 KB
testcase_01 AC 126 ms
56,072 KB
testcase_02 AC 813 ms
61,256 KB
testcase_03 AC 660 ms
61,284 KB
testcase_04 AC 558 ms
61,096 KB
testcase_05 AC 524 ms
61,288 KB
testcase_06 AC 324 ms
59,212 KB
testcase_07 AC 172 ms
56,176 KB
testcase_08 AC 343 ms
59,332 KB
testcase_09 AC 769 ms
61,544 KB
testcase_10 AC 125 ms
56,064 KB
testcase_11 AC 876 ms
61,016 KB
testcase_12 AC 866 ms
60,788 KB
testcase_13 AC 741 ms
60,576 KB
testcase_14 AC 787 ms
61,544 KB
testcase_15 AC 766 ms
61,452 KB
testcase_16 AC 196 ms
58,156 KB
testcase_17 AC 658 ms
61,724 KB
testcase_18 AC 568 ms
61,160 KB
testcase_19 AC 202 ms
57,656 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