結果

問題 No.9 モンスターのレベル上げ
ユーザー mastersatoshi
提出日時 2015-08-03 14:22:26
言語 Java
(openjdk 23)
結果
AC  
実行時間 835 ms / 5,000 ms
コード長 2,114 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 78,676 KB
実行使用メモリ 49,480 KB
最終ジャッジ日時 2024-06-23 22:46:06
合計ジャッジ時間 12,081 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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