結果

問題 No.9 モンスターのレベル上げ
ユーザー gigurururugigurururu
提出日時 2015-01-28 17:39:00
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 969 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 11,580 KB
実行使用メモリ 51,712 KB
最終ジャッジ日時 2023-09-05 07:25:41
合計ジャッジ時間 41,217 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,072 KB
testcase_01 AC 83 ms
15,336 KB
testcase_02 AC 3,842 ms
51,572 KB
testcase_03 AC 3,037 ms
40,212 KB
testcase_04 AC 1,632 ms
32,740 KB
testcase_05 AC 1,123 ms
30,404 KB
testcase_06 AC 437 ms
20,580 KB
testcase_07 AC 90 ms
15,408 KB
testcase_08 AC 561 ms
22,512 KB
testcase_09 AC 3,720 ms
49,900 KB
testcase_10 AC 81 ms
15,236 KB
testcase_11 AC 3,862 ms
51,608 KB
testcase_12 TLE -
testcase_13 AC 3,635 ms
51,608 KB
testcase_14 AC 3,733 ms
49,832 KB
testcase_15 AC 3,415 ms
45,852 KB
testcase_16 AC 140 ms
15,912 KB
testcase_17 AC 2,223 ms
37,336 KB
testcase_18 AC 1,940 ms
35,932 KB
testcase_19 AC 118 ms
15,468 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class BinHeap
  def initialize(buf=nil)
    @buf=buf||[nil]
    @max=@buf.size
  end
  def add(n)
#    print :add_s,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
#    print :add_e,n
  end
  def get
#    print :get_s
    ret=@buf[1]
    a=@buf[i=1]=@buf[l=@max-=1]
    while (c=i*2)<l
      c+=1 if c+1<l && @buf[c]>@buf[c+1]
      if a>b=@buf[c]
        @buf[i]=b
        i=c
      else
        break
      end
    end
    @buf[i]=a
#    print :get_e,ret
    ret
  end
  def dup
    BinHeap.new(@buf[0..@max-1])
  end
  def buf
    @buf
  end
  def print(*arg)
    p arg*" "
    i=s=1
    while i<@max
      p @buf[i,s]
      i+=s
      s*=2
    end
  end
end
n=gets.to_i
mod=2000
pq_base=BinHeap.new
gets.split.each{|i|pq_base.add i.to_i*mod}
b=gets.split.map{|i|i.to_i/2*mod}
p (1..n).map{|i|
  pq=pq_base.dup
  b.rotate(i).each{|e|
    pq.add pq.get+e+1
  }
  pq.buf[1..-1].map{|x|x%mod}.max
}.min
0