結果

問題 No.9 モンスターのレベル上げ
ユーザー gigurururugigurururu
提出日時 2015-01-29 18:29:51
言語 Ruby
(3.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 514 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 11,444 KB
実行使用メモリ 51,732 KB
最終ジャッジ日時 2023-09-06 03:32:49
合計ジャッジ時間 32,618 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,116 KB
testcase_01 AC 76 ms
15,048 KB
testcase_02 AC 2,999 ms
51,728 KB
testcase_03 AC 2,368 ms
42,520 KB
testcase_04 AC 1,291 ms
31,712 KB
testcase_05 AC 890 ms
30,460 KB
testcase_06 AC 354 ms
20,728 KB
testcase_07 AC 85 ms
15,296 KB
testcase_08 AC 459 ms
22,664 KB
testcase_09 AC 2,950 ms
49,704 KB
testcase_10 AC 80 ms
15,340 KB
testcase_11 AC 2,926 ms
51,564 KB
testcase_12 TLE -
testcase_13 AC 2,757 ms
51,552 KB
testcase_14 AC 2,928 ms
49,784 KB
testcase_15 AC 2,657 ms
45,872 KB
testcase_16 AC 137 ms
15,860 KB
testcase_17 AC 1,761 ms
38,772 KB
testcase_18 AC 1,475 ms
33,816 KB
testcase_19 AC 103 ms
15,864 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}
p (1..n).map{|i|
  pq=pq_base.dup
  el.rotate(i).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]
    pq[i]=d
  }
  pq[1..-2].map{|x|x&bmask}.max
}.min
0