結果

問題 No.9 モンスターのレベル上げ
ユーザー gigurururugigurururu
提出日時 2015-01-29 18:17:44
言語 Ruby
(3.2.2)
結果
RE  
実行時間 -
コード長 979 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 11,508 KB
実行使用メモリ 56,376 KB
最終ジャッジ日時 2023-09-05 07:42:06
合計ジャッジ時間 14,637 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
28,824 KB
testcase_01 AC 104 ms
28,848 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 361 ms
28,432 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 93 ms
28,540 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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}
counts = []
pids = {}
max_procs = 4
(1..n).each{|i|
  if pids.size >= max_procs
    pid = Process.wait
    counts << pids[pid].gets.to_i
    pids[pid].close
    pids.delete(pid)
  end
  read, write = IO.pipe
  pid = fork{
    read.close
    pq=pq_base
    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/=2 while i>1 && d<pq[i]=pq[i/2]
      pq[i]=d
    }
    write.puts(pq[1..-2].map{|x|x&bmask}.max)
    write.close
  }
  if pids.key?(pid)
    counts << pids[pid].gets.to_i
    pids[pid].close
  else
    pids[pid] = read
  end
}
Process.waitall.each do |pst|
  counts << pids[pst[0]].gets.to_i
end
puts counts.min
0