結果
問題 | No.9 モンスターのレベル上げ |
ユーザー |
|
提出日時 | 2016-03-05 19:48:05 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 753 ms / 5,000 ms |
コード長 | 2,724 bytes |
コンパイル時間 | 4,579 ms |
コンパイル使用メモリ | 79,840 KB |
実行使用メモリ | 59,792 KB |
最終ジャッジ日時 | 2024-06-23 23:20:20 |
合計ジャッジ時間 | 13,317 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.PriorityQueue; public class Main_yukicoder9 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); List<Integer> a = new ArrayList<Integer>(); List<Integer> b = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { a.add(sc.nextInt()); } for (int i = 0; i < n; i++) { b.add(sc.nextInt()); } int min = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { PriorityQueue<Monster> pq = new PriorityQueue<Monster>(); for (int j = 0; j < n; j++) { pq.add(new Monster(a.get(j))); } int max = 0; for (int j = 0; j < n; j++) { Monster m = pq.remove(); m.lv += b.get((i + j) % n) / 2; m.cnt++; max = Math.max(max, m.cnt); pq.add(m); } min = Math.min(min, max); } pr.println(min); pr.close(); sc.close(); } private static class Monster implements Comparable<Monster> { int lv; int cnt; Monster(int lv) { this.lv = lv; cnt = 0; } @Override public int compareTo(Monster o) { if (this.lv != o.lv) { return Integer.compare(this.lv, o.lv); } return Integer.compare(this.cnt, o.cnt); } } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }