結果
問題 | No.9 モンスターのレベル上げ |
ユーザー |
|
提出日時 | 2014-11-12 03:31:30 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,111 ms / 5,000 ms |
コード長 | 1,934 bytes |
コンパイル時間 | 2,257 ms |
コンパイル使用メモリ | 79,140 KB |
実行使用メモリ | 60,844 KB |
最終ジャッジ日時 | 2024-06-23 22:05:03 |
合計ジャッジ時間 | 15,490 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
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; } } }