結果

問題 No.9 モンスターのレベル上げ
ユーザー mbanmban
提出日時 2017-04-11 20:55:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 773 ms / 5,000 ms
コード長 1,590 bytes
コンパイル時間 4,530 ms
コンパイル使用メモリ 75,428 KB
実行使用メモリ 60,928 KB
最終ジャッジ日時 2023-09-06 05:14:09
合計ジャッジ時間 13,079 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,280 KB
testcase_01 AC 124 ms
55,872 KB
testcase_02 AC 587 ms
60,584 KB
testcase_03 AC 412 ms
60,440 KB
testcase_04 AC 410 ms
60,056 KB
testcase_05 AC 382 ms
60,364 KB
testcase_06 AC 268 ms
58,960 KB
testcase_07 AC 139 ms
56,136 KB
testcase_08 AC 264 ms
59,376 KB
testcase_09 AC 567 ms
60,372 KB
testcase_10 AC 125 ms
55,728 KB
testcase_11 AC 569 ms
60,464 KB
testcase_12 AC 773 ms
60,928 KB
testcase_13 AC 214 ms
57,532 KB
testcase_14 AC 543 ms
60,748 KB
testcase_15 AC 569 ms
60,872 KB
testcase_16 AC 196 ms
55,508 KB
testcase_17 AC 495 ms
60,368 KB
testcase_18 AC 420 ms
60,080 KB
testcase_19 AC 182 ms
55,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Program {
	public static void main(String[] args) {
		new Magatro().solve();
	}
}

class Magatro {
	private int n;
	private int[] a, b;
	private PriorityQueue<Mon> priorityQueue;
	private int anser = Integer.MAX_VALUE;

	private void scan() {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		a = new int[n];
		b = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		for (int i = 0; i < n; i++) {
			b[i] = scanner.nextInt();
		}
	}

	private void battle(int start) {
		int result = -1;
		PriorityQueue<Mon> copyPq = new PriorityQueue<Mon>(priorityQueue);
		for (int i = 0; i < n; i++) {
			int index = (i+start)%n;
			Mon mon = copyPq.poll();
			Mon mon2 = new Mon(mon.level+b[index]/2,mon.battle+1);
			result = Math.max(mon2.battle, result);
			if(anser<=result)return;
			copyPq.add(mon2);
		}
		anser = result;
	}

	public void solve() {
		scan();

		priorityQueue = new PriorityQueue<>(1, new MyComparator());
		for (int i : a) {
			priorityQueue.add(new Mon(i));
		}
		
		for(int i=0;i<n;i++){
			battle(i);
		}
		System.out.println(anser);
	}
}

class MyComparator implements Comparator<Mon> {
	public int compare(Mon a, Mon b) {
		if (a.level != b.level) {
			return Integer.compare(a.level, b.level);
		} else {
			return Integer.compare(a.battle, b.battle);
		}
	}
}

class Mon {
	public int level;
	public int battle;

	public Mon(int l) {
		level = l;
		battle = 0;
	}
	public Mon (int l,int b) {
		level = l;
		battle = b;
	}
}
0