結果

問題 No.9 モンスターのレベル上げ
ユーザー mastersatoshimastersatoshi
提出日時 2015-08-03 14:22:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 801 ms / 5,000 ms
コード長 2,114 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 74,828 KB
実行使用メモリ 60,216 KB
最終ジャッジ日時 2023-09-06 03:56:39
合計ジャッジ時間 12,183 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,368 KB
testcase_01 AC 43 ms
49,432 KB
testcase_02 AC 801 ms
60,204 KB
testcase_03 AC 702 ms
59,892 KB
testcase_04 AC 501 ms
60,216 KB
testcase_05 AC 460 ms
59,540 KB
testcase_06 AC 241 ms
57,604 KB
testcase_07 AC 80 ms
51,780 KB
testcase_08 AC 283 ms
58,464 KB
testcase_09 AC 799 ms
60,016 KB
testcase_10 AC 42 ms
49,408 KB
testcase_11 AC 768 ms
59,024 KB
testcase_12 AC 774 ms
58,244 KB
testcase_13 AC 651 ms
59,348 KB
testcase_14 AC 793 ms
59,988 KB
testcase_15 AC 765 ms
59,956 KB
testcase_16 AC 121 ms
53,880 KB
testcase_17 AC 568 ms
60,020 KB
testcase_18 AC 505 ms
60,076 KB
testcase_19 AC 105 ms
52,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(br.readLine());

        String[] A = br.readLine().split(" ");
        String[] B = br.readLine().split(" ");

        int miniMax = Integer.MAX_VALUE;

        for (int i = 0; i < N; i++) {

            PriorityQueue<D> pq = new PriorityQueue();

            for (int j = 0; j < N; j++) {
                D a = new D(new int[]{Integer.parseInt(A[j]), 0});
                pq.add(a);
            }

            int tmpMax = 0;
            for (int j = 0; j < N; j++) {
                int enemy = i + j;
                if (enemy >= N) {
                    enemy = enemy - N;
                }

                D tmp = pq.poll();

                tmp.a[0] = tmp.a[0] + (Integer.parseInt(B[enemy]) / 2);
                tmp.a[1] = tmp.a[1] + 1;

                if (tmpMax < tmp.a[1]) {
                    tmpMax = tmp.a[1];
                }

                pq.add(tmp);
            }

            if (miniMax > tmpMax) {
                miniMax = tmpMax;
            }
        }

        System.out.println(miniMax);
    }

    static class D implements Comparable<D> {

        int[] a;

        public D(int[] a) {
            this.a = a;
        }

        //比較メソッド(データクラスを比較して-1, 0, 1を返すように記述する)
        public int compareTo(D b) {
            int no1 = a[0];
            int no2 = b.a[0];
            int no3 = a[1];
            int no4 = b.a[1];

            //こうすると社員番号の昇順でソートされる
            if (no1 > no2) {
                return 1;

            } else if (no1 == no2) {
                if (no3 > no4) {
                    return 1;

                } else if (no3 == no4) {
                    return 0;

                } else {
                    return -1;

                }

            } else {
                return -1;

            }
        }
    }
}
0