結果

問題 No.9 モンスターのレベル上げ
ユーザー gigurururu
提出日時 2015-01-29 20:26:41
言語 Ruby
(3.4.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 768 bytes
コンパイル時間 55 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 25,344 KB
最終ジャッジ日時 2024-06-23 04:03:14
合計ジャッジ時間 32,139 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 TLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class BinHeap
  def initialize(buf=nil)
    @buf=buf||[nil]
    @max=@buf.size
  end
  def add(n)
    a=@buf[i=@max]=n
    @max+=1
    while i>1 && a<b=@buf[i/2]
      @buf[i]=b
      i/=2
    end
    @buf[i]=a
  end
  def get
    ret=@buf[1]
    a=@buf[i=1]=@buf[l=@max-=1]
    while (c=i*2)<l
      c+=1 if @buf[c]>(@buf[c+1]||1e9)
      break if a<=b=@buf[c]
      @buf[i]=b
      i=c
    end
    @buf[i]=a
    ret
  end
  def dup
    BinHeap.new(@buf[0..@max-1])
  end
end
n=gets.to_i
pq_base=BinHeap.new
gets.split.each{|i|pq_base.add(i.to_i<<11)}
b=gets.split.map{|i|i.to_i/2<<11}
min=1e9
n.times{
  pq=pq_base.dup
  max=0
  b.rotate!.each{|e|
    pq.add(top=pq.get+e+1)
    top&=0x7FF
    max=top if max<top
    break if min<top
  }
  min=max if min>max
}
p min
0