結果

問題 No.9 モンスターのレベル上げ
ユーザー ゆうきゆうき
提出日時 2022-10-21 03:49:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,552 ms / 5,000 ms
コード長 5,201 bytes
コンパイル時間 2,550 ms
コンパイル使用メモリ 82,624 KB
実行使用メモリ 61,304 KB
最終ジャッジ日時 2023-09-13 07:02:17
合計ジャッジ時間 18,433 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
53,780 KB
testcase_01 AC 101 ms
53,868 KB
testcase_02 AC 1,327 ms
60,196 KB
testcase_03 AC 1,107 ms
59,868 KB
testcase_04 AC 668 ms
59,964 KB
testcase_05 AC 492 ms
60,148 KB
testcase_06 AC 294 ms
59,752 KB
testcase_07 AC 154 ms
58,636 KB
testcase_08 AC 335 ms
59,836 KB
testcase_09 AC 1,306 ms
60,240 KB
testcase_10 AC 103 ms
54,436 KB
testcase_11 AC 1,493 ms
60,096 KB
testcase_12 AC 1,552 ms
60,332 KB
testcase_13 AC 1,291 ms
61,304 KB
testcase_14 AC 1,267 ms
60,436 KB
testcase_15 AC 1,185 ms
60,060 KB
testcase_16 AC 198 ms
58,012 KB
testcase_17 AC 847 ms
60,044 KB
testcase_18 AC 743 ms
60,116 KB
testcase_19 AC 194 ms
59,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.function.IntFunction;

class Main{
  boolean isDebug = ManagementFactory.getRuntimeMXBean().getInputArguments().toString()
      .contains("-agentlib:jdwp");
  final MyReader in = new MyReader(System.in);
  final MyWriter out = new MyWriter(System.out);

  public static void main(final String[] args){ new Main().exe(); }

  private void exe(){
    input();
    preCalc();
    solve();
    out.flush();
  }

  int N = in.it();
  int[] A = in.it(N);
  int[] B = in.it(N);

  private void input(){}

  private void preCalc(){}

  void solve(){
    int ans = Integer.MAX_VALUE;
    for (int i = 0;i < N;i++) {
      Comparator<int[]> comparing = Comparator.comparing(t -> t[0]);
      Queue<int[]> que = new PriorityQueue<>(comparing.thenComparing(Comparator.comparing(t -> t[1])));
      for (var a:A)
        que.add(new int[] { a, 0 });

      int tmp = 0;
      for (int j = 0;j < N;j++) {
        int b = B[(i +j) %N];
        int[] t = que.poll();
        t[0] += b /2;
        t[1]++;
        tmp = Math.max(tmp,t[1]);
        que.add(t);
      }
      ans = Math.min(ans,tmp);
    }
    out.println(ans);
  }

  /* 定数 */
  final int mod = (int) (1e9 +7);
  final String yes = "Yes";
  final String no = "No";

  /* 入力 */
  static class MyReader{
    byte[] buf = new byte[1 <<16];
    int head = 0;
    int tail = 0;
    InputStream in;

    public MyReader(final InputStream in){ this.in = in; }

    byte read(){
      if (head == tail) {
        try {
          tail = in.read(buf);
        } catch (IOException e) {
          e.printStackTrace();
        }
        head = 0;
      }
      return buf[head++];
    }

    boolean isPrintable(final byte c){ return 32 < c && c < 127; }

    boolean isNum(final byte c){ return 47 < c && c < 58; }

    byte nextPrintable(){
      byte ret = read();
      return isPrintable(ret) ? ret : nextPrintable();
    }

    int it(){ return (int) lg(); }

    int[] it(final int N){
      int[] a = new int[N];
      Arrays.setAll(a,i -> it());
      return a;
    }

    int[][] it(final int H,final int W){ return arr(new int[H][],i -> it(W)); }

    int idx(){ return it() -1; }

    int[] idx(final int N){
      int[] a = new int[N];
      Arrays.setAll(a,i -> idx());
      return a;
    }

    int[][] idx(final int H,final int W){ return arr(new int[H][],i -> idx(W)); }

    long lg(){
      byte i = nextPrintable();
      boolean negative = i == 45;
      long n = negative ? 0 : i -'0';
      while (isPrintable(i = read()))
        n = 10 *n +i -'0';
      return negative ? -n : n;
    }

    long[] lg(final int N){
      long[] a = new long[N];
      Arrays.setAll(a,i -> lg());
      return a;
    }

    long[][] lg(final int H,final int W){ return arr(new long[H][],i -> lg(W)); }

    char[] ch(){ return str().toCharArray(); }

    char[][] ch(final int H){ return arr(new char[H][],i -> ch()); }

    String line(){
      StringBuilder sb = new StringBuilder();

      byte c;
      while (isPrintable(c = read()) || c == ' ')
        sb.append((char) c);
      return sb.toString();
    }

    String str(){
      StringBuilder sb = new StringBuilder();
      sb.append((char) nextPrintable());
      byte c;
      while (isPrintable(c = read()))
        sb.append((char) c);
      return sb.toString();
    }

    String[] str(final int N){ return arr(new String[N],i -> str()); }

    <T> T[] arr(final T[] arr,final IntFunction<T> f){
      Arrays.setAll(arr,f);
      return arr;
    }
  }

  /* 出力 */
  static class MyWriter{
    OutputStream out;

    byte[] buf = new byte[1 <<16];
    byte[] ibuf = new byte[20];

    int tail = 0;

    public MyWriter(final OutputStream out){ this.out = out; }

    void flush(){
      try {
        out.write(buf,0,tail);
        tail = 0;
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    void write(final byte b){
      buf[tail++] = b;
      if (tail == buf.length)
        flush();
    }

    void write(final byte[] b,final int off,final int len){
      for (int i = off;i < off +len;i++)
        write(b[i]);
    }

    void write(final char c){ write((byte) c); }

    void write(long n){
      if (n < 0) {
        n = -n;
        write('-');
      }

      int i = ibuf.length;
      do {
        ibuf[--i] = (byte) (n %10 +'0');
        n /= 10;
      } while (n > 0);

      write(ibuf,i,ibuf.length -i);
    }

    void println(final long n){
      write(n);
      write('\n');
    }

    public void println(final double d){ println(String.valueOf(d)); }

    void println(final String s){
      byte[] b = s.getBytes();
      for (byte bb:b)
        write(bb);
      write('\n');
    }

    public void println(final char[] s){
      for (char bb:s)
        write(bb);
      write('\n');
    }

    void println(final int[] a){
      for (int i = 0;i < a.length;i++) {
        if (0 < i)
          write(' ');
        write(a[i]);
      }
      write('\n');
    }

  }
}
0