結果

問題 No.9 モンスターのレベル上げ
ユーザー gigurururugigurururu
提出日時 2015-01-29 19:00:35
言語 Ruby
(3.2.2)
結果
AC  
実行時間 4,957 ms / 5,000 ms
コード長 540 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 11,340 KB
実行使用メモリ 31,976 KB
最終ジャッジ日時 2023-09-06 03:32:01
合計ジャッジ時間 32,182 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,144 KB
testcase_01 AC 83 ms
15,164 KB
testcase_02 AC 2,886 ms
31,764 KB
testcase_03 AC 2,300 ms
29,168 KB
testcase_04 AC 1,254 ms
22,800 KB
testcase_05 AC 852 ms
20,564 KB
testcase_06 AC 346 ms
17,068 KB
testcase_07 AC 89 ms
15,076 KB
testcase_08 AC 438 ms
17,580 KB
testcase_09 AC 2,847 ms
31,708 KB
testcase_10 AC 86 ms
15,148 KB
testcase_11 AC 2,858 ms
31,876 KB
testcase_12 AC 4,957 ms
31,976 KB
testcase_13 AC 2,757 ms
31,696 KB
testcase_14 AC 2,826 ms
31,664 KB
testcase_15 AC 2,569 ms
30,988 KB
testcase_16 AC 123 ms
15,444 KB
testcase_17 AC 1,705 ms
25,592 KB
testcase_18 AC 1,483 ms
24,112 KB
testcase_19 AC 105 ms
15,364 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n=gets.to_i
bs=11
bmask=(1<< bs)-1

pq_base=[nil]
gets.split.each.with_index(1){|j,i|
  a=j.to_i<< bs
  i/=2 while i>1 && a<pq_base[i]=pq_base[i/2]
  pq_base[i]=a
}
pq_base<<1e9

el=gets.split.map{|i|(i.to_i/2<< bs)+1}
min=1e9
n.times{
  max=0
  pq=pq_base.dup
  el.rotate!.each{|e|
    a=pq[n]
    d=pq[i=1]+e
    while (c=i*2)<n
      c+=1 if pq[c]>pq[c+1]
      break if a<=pq[i]=pq[c]
      i=c
    end
    pq[i]=a
    i=n
    i>>=1 while i>1 && d<pq[i]=pq[i>>1]
    x=(pq[i]=d)&bmask
    max=x if max<x
  }
  min=max if min>max
}
p min
0