結果

問題 No.9 モンスターのレベル上げ
ユーザー GrenacheGrenache
提出日時 2016-03-05 19:48:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 808 ms / 5,000 ms
コード長 2,724 bytes
コンパイル時間 3,831 ms
コンパイル使用メモリ 76,980 KB
実行使用メモリ 59,172 KB
最終ジャッジ日時 2023-09-06 04:30:51
合計ジャッジ時間 13,636 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
49,728 KB
testcase_01 AC 48 ms
49,460 KB
testcase_02 AC 772 ms
58,788 KB
testcase_03 AC 670 ms
59,016 KB
testcase_04 AC 439 ms
58,572 KB
testcase_05 AC 359 ms
58,616 KB
testcase_06 AC 231 ms
58,500 KB
testcase_07 AC 77 ms
51,700 KB
testcase_08 AC 245 ms
58,000 KB
testcase_09 AC 808 ms
59,172 KB
testcase_10 AC 48 ms
47,448 KB
testcase_11 AC 802 ms
58,868 KB
testcase_12 AC 773 ms
58,844 KB
testcase_13 AC 554 ms
58,384 KB
testcase_14 AC 804 ms
59,000 KB
testcase_15 AC 699 ms
58,996 KB
testcase_16 AC 119 ms
53,364 KB
testcase_17 AC 549 ms
58,988 KB
testcase_18 AC 476 ms
58,764 KB
testcase_19 AC 102 ms
52,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.PriorityQueue;


public class Main_yukicoder9 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Printer pr = new Printer(System.out);

        int n = sc.nextInt();

        List<Integer> a = new ArrayList<Integer>();
        List<Integer> b = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
        	a.add(sc.nextInt());
        }
        for (int i = 0; i < n; i++) {
        	b.add(sc.nextInt());
        }

        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
        	PriorityQueue<Monster> pq = new PriorityQueue<Monster>();
        	for (int j = 0; j < n; j++) {
        		pq.add(new Monster(a.get(j)));
        	}

        	int max = 0;
        	for (int j = 0; j < n; j++) {
        		Monster m = pq.remove();

        		m.lv += b.get((i + j) % n) / 2;
        		m.cnt++;
        		max = Math.max(max, m.cnt);

        		pq.add(m);
        	}

        	min = Math.min(min, max);
        }

        pr.println(min);

        pr.close();
        sc.close();
    }

    private static class Monster implements Comparable<Monster> {
    	int lv;
    	int cnt;

    	Monster(int lv) {
    		this.lv = lv;
    		cnt = 0;
    	}

		@Override
		public int compareTo(Monster o) {
			if (this.lv != o.lv) {
				return Integer.compare(this.lv, o.lv);
			}

			return Integer.compare(this.cnt, o.cnt);
		}
    }

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0