結果

問題 No.9 モンスターのレベル上げ
ユーザー scachescache
提出日時 2014-11-12 03:31:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,157 ms / 5,000 ms
コード長 1,934 bytes
コンパイル時間 2,047 ms
コンパイル使用メモリ 79,824 KB
実行使用メモリ 63,888 KB
最終ジャッジ日時 2023-09-06 03:13:33
合計ジャッジ時間 16,174 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,912 KB
testcase_01 AC 123 ms
56,028 KB
testcase_02 AC 1,100 ms
62,380 KB
testcase_03 AC 1,020 ms
62,220 KB
testcase_04 AC 701 ms
63,032 KB
testcase_05 AC 600 ms
62,580 KB
testcase_06 AC 394 ms
62,084 KB
testcase_07 AC 174 ms
53,900 KB
testcase_08 AC 442 ms
60,212 KB
testcase_09 AC 1,059 ms
62,944 KB
testcase_10 AC 121 ms
55,600 KB
testcase_11 AC 1,102 ms
61,976 KB
testcase_12 AC 1,077 ms
63,888 KB
testcase_13 AC 761 ms
62,324 KB
testcase_14 AC 1,157 ms
62,652 KB
testcase_15 AC 1,067 ms
62,540 KB
testcase_16 AC 220 ms
58,104 KB
testcase_17 AC 843 ms
62,380 KB
testcase_18 AC 724 ms
62,828 KB
testcase_19 AC 202 ms
56,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}
 
	public Main() {
		long startTime = System.currentTimeMillis();
		solve();
		long endTime = System.currentTimeMillis();
		// System.out.println((endTime-startTime)/1000.0);
 
	}
 
	public void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
 
		Monster[] monsters = new Monster[n];
		for(int i=0;i<n;i++){
			monsters[i] = new Monster(sc.nextInt());
		}
 
		Monster[] enemies = new Monster[n];
		for(int i=0;i<n;i++){
//			enemies[i] = new Monster(sc.nextInt());
			enemies[i] = new Monster(sc.nextInt()/2);
		}
 
		int res = Integer.MAX_VALUE;
 
		for(int i=0;i<n;i++){
			PriorityQueue<Monster> cur = new PriorityQueue<Monster>(n, new MonsterComparator());
 
			// Monster[] newMonsters = monsters.clone();
			// for(int j=0;j<n;j++){
			// 	cur.offer(newMonsters[j]);
			// }
			for(int j=0;j<n;j++){
				cur.offer(new Monster(monsters[j].level));
			}
			for(int j=0;j<n;j++){
				Monster m = cur.poll();
//				m.level += enemies[(i+j)%n].level/2;
				m.level += enemies[(i+j)%n].level;
				m.encount++;
 
				cur.offer(m);
			}
 
			int maxEncount = 0;
			while(!cur.isEmpty()){
				maxEncount = Math.max(maxEncount, cur.poll().encount);
			}
			res = Math.min(res, maxEncount);
		}
 
		System.out.println(res);
 
	}
 
	private class Monster{
		public int level;
		public int encount;
 
		public Monster(int level){
			this.level = level;
			this.encount = 0;
		}
	}
 
	private class MonsterComparator implements java.util.Comparator<Monster>{
 
		@Override
		public int compare(Monster o1, Monster o2) {
			if(o1.level!=o2.level)
				return o1.level-o2.level;
			else
				return o1.encount-o2.encount;
		}
 
	}
}
 
0