結果
問題 | No.9 モンスターのレベル上げ |
ユーザー |
|
提出日時 | 2015-01-28 17:39:00 |
言語 | Ruby (3.4.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 969 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 41,984 KB |
最終ジャッジ日時 | 2024-06-23 03:38:30 |
合計ジャッジ時間 | 26,481 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 TLE * 1 -- * 7 |
コンパイルメッセージ
Syntax OK
ソースコード
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