結果

問題 No.9 モンスターのレベル上げ
ユーザー mastersatoshimastersatoshi
提出日時 2015-08-03 14:22:26
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 812 ms / 5,000 ms
コード長 2,114 bytes
コンパイル時間 1,668 ms
使用メモリ 46,348 KB
最終ジャッジ日時 2023-01-21 14:43:26
合計ジャッジ時間 11,937 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 49 ms
34,052 KB
testcase_01 AC 49 ms
34,220 KB
testcase_02 AC 812 ms
46,264 KB
testcase_03 AC 645 ms
44,876 KB
testcase_04 AC 527 ms
46,140 KB
testcase_05 AC 439 ms
46,348 KB
testcase_06 AC 240 ms
44,504 KB
testcase_07 AC 84 ms
35,076 KB
testcase_08 AC 288 ms
44,052 KB
testcase_09 AC 758 ms
44,628 KB
testcase_10 AC 50 ms
34,176 KB
testcase_11 AC 772 ms
45,328 KB
testcase_12 AC 698 ms
44,872 KB
testcase_13 AC 687 ms
45,136 KB
testcase_14 AC 796 ms
45,332 KB
testcase_15 AC 706 ms
44,088 KB
testcase_16 AC 137 ms
37,976 KB
testcase_17 AC 584 ms
46,332 KB
testcase_18 AC 554 ms
46,212 KB
testcase_19 AC 134 ms
37,068 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