結果

問題 No.9 モンスターのレベル上げ
ユーザー jp_ste
提出日時 2020-05-14 21:05:03
言語 Java
(openjdk 23)
結果
AC  
実行時間 767 ms / 5,000 ms
コード長 1,429 bytes
コンパイル時間 3,330 ms
コンパイル使用メモリ 78,140 KB
実行使用メモリ 49,872 KB
最終ジャッジ日時 2024-09-15 21:18:18
合計ジャッジ時間 13,448 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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