結果

問題 No.9 モンスターのレベル上げ
コンテスト
ユーザー yuki2006
提出日時 2014-10-11 04:50:10
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,974 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 483 ms
コンパイル使用メモリ 36,112 KB
最終ジャッジ日時 2026-03-09 05:53:00
合計ジャッジ時間 774 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
[0.027s][warning][os,thread] Failed to start thread "Unknown thread" - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 4k, detached.
Error occurred during initialization of VM
java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached

ソースコード

diff #
raw source code

import java.util.Date;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Yuki009 {


    static class Tuple implements Comparable<Tuple> {
        int level;
        int count;

        Tuple(int level, int count) {
            this.level = level;
            this.count = count;
        }

        @Override
        public int compareTo(Tuple o) {
            int value = Integer.compare(level, o.level);
            if (value == 0) {
                return Integer.compare(count, o.count);
            }
            return value;
        }
    }

    static int N = 1500;


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        N = scanner.nextInt();
        int[] party = new int[N + 1];
        int[] enemy = new int[N + 1];
        long exec_time = new Date().getTime();

        for (int i = 0; i < N; i++) {
            party[i] = scanner.nextInt();
        }
        for (int i = 0; i < N; i++) {
            enemy[i] = scanner.nextInt();
        }
        int min = N;

        for (int i = 0; i < N; i++) {
            PriorityQueue<Tuple> queue = new PriorityQueue<Tuple>(N);
            for (int k = 0; k < N; k++) {
                queue.add(new Tuple(party[k], 0));
            }

            for (int j = 0; j < N; j++) {
                Tuple t = queue.poll();
                t.level += enemy[(i + j) % N] / 2;
                t.count++;
                queue.add(t);
            }
            //最後に一番試合数が要素を見つけるので配列に起こす。
            Tuple[] tuples = queue.toArray(new Tuple[0]);
            int max = 0;
            for (Tuple t : tuples) {
                max = Math.max(max, t.count);
            }
            min = Math.min(min, max);
        }
        System.out.println(min);
        System.err.println(new Date().getTime() - exec_time + "ms");


    }


}
0