結果

問題 No.9 モンスターのレベル上げ
ユーザー jp_stejp_ste
提出日時 2020-05-14 21:05:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 907 ms / 5,000 ms
コード長 1,429 bytes
コンパイル時間 2,591 ms
コンパイル使用メモリ 74,660 KB
実行使用メモリ 63,176 KB
最終ジャッジ日時 2023-10-14 01:33:39
合計ジャッジ時間 15,274 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,236 KB
testcase_01 AC 129 ms
55,912 KB
testcase_02 AC 829 ms
60,788 KB
testcase_03 AC 820 ms
62,840 KB
testcase_04 AC 600 ms
62,988 KB
testcase_05 AC 511 ms
63,100 KB
testcase_06 AC 319 ms
60,632 KB
testcase_07 AC 169 ms
55,836 KB
testcase_08 AC 372 ms
60,968 KB
testcase_09 AC 907 ms
62,912 KB
testcase_10 AC 126 ms
55,988 KB
testcase_11 AC 877 ms
62,040 KB
testcase_12 AC 882 ms
62,636 KB
testcase_13 AC 748 ms
62,260 KB
testcase_14 AC 884 ms
62,980 KB
testcase_15 AC 859 ms
62,636 KB
testcase_16 AC 196 ms
58,024 KB
testcase_17 AC 712 ms
63,176 KB
testcase_18 AC 617 ms
62,708 KB
testcase_19 AC 207 ms
55,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	static Scanner scan = new Scanner(System.in);
	static PriorityQueue<Node> q = new PriorityQueue<>();
	static int N;
	static int[] A, B;
	
	public static void main(String[] args) {
		input();
		solve();
	}
	
	static void input() {
		N = scan.nextInt();
		A = new int[N];
		B = new int[N];
		for(int i=0; i<N; i++) A[i] = scan.nextInt();
		for(int i=0; i<N; i++) B[i] = scan.nextInt();
	}
	
	static void solve() {
		int ansCount = Integer.MAX_VALUE;
		for(int nowIndex=0; nowIndex<N; nowIndex++) {
			q.clear();
			for(int i=0; i<N; i++) {
			    q.add(new Node(A[i], 0));
			}
			int endIndex = nowIndex;
			int maxCount = 0;
			while(true) {
				int level = B[nowIndex];
				Node frend = q.poll();
				frend.gain(level);
				maxCount = Math.max(maxCount, frend.count);
				q.add(frend);
				nowIndex = (nowIndex + 1) % N;
				if(nowIndex == endIndex) break;
			}
			ansCount = Math.min(ansCount, maxCount);
		}
		System.out.println(ansCount);
	}
	
	static class Node implements Comparable<Node> {
		int level;
		int count;
		Node(int level, int count) {
			this.level = level;
			this.count = count;
		}
		void gain(int level) {
			this.level += level / 2;
			this.count++;
		}
		@Override
		public int compareTo(Node other) {
			if(this.level == other.level) {
				return this.count - other.count;
			}
			return this.level - other.level;
		}
	}
}
0