結果

問題 No.9 モンスターのレベル上げ
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2015-01-28 00:05:02
言語 Ruby
(3.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,959 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 11,224 KB
実行使用メモリ 55,872 KB
最終ジャッジ日時 2023-09-06 03:27:05
合計ジャッジ時間 6,600 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
28,200 KB
testcase_01 AC 83 ms
28,252 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 151 ms
28,184 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 78 ms
28,240 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 #

# start_time = Time.now
n = gets.to_i
n0 = 11
n1 = 2 ** n0
org_mon_list = [0]
gets.split.each do |level|
  point = level.to_i << n0
  i = org_mon_list.size
  org_mon_list << point
  while i > 1
    j = i / 2
    parent = org_mon_list[j]
    if point < parent
      org_mon_list[i] = parent
      org_mon_list[j] = point
      i = j
    else
      break
    end
  end
end
org_mon_list << ((10001 + 5000 * n) << n0)
exp_list = gets.split.map{|s|s.to_i / 2}
# low_count = 1500
counts = []
pids = {}
max_procs = 4
n.times do |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 do
    read.close
    mon_list = org_mon_list.clone
    max_count = 0
    n.times do |j|
      exp = exp_list[(i + j) % n]
      target = mon_list[1] + (exp << n0) + 1
      count = target % n1
      max_count = count if count > max_count
      k = 1
      mon_list[1] = target
      while (k0 = 2 * k) <= n
        k1 = k0 + 1
        k0_mon = mon_list[k0]
        k1_mon = mon_list[k1]
        if k0_mon < target
          if k1_mon < target
            if k0_mon < k1_mon
              mon_list[k] = k0_mon
              mon_list[k0] = target
              k = k0
            else
              mon_list[k] = k1_mon
              mon_list[k1] = target
              k = k1
            end
          else
            mon_list[k] = k0_mon
            mon_list[k0] = target
            k = k0
          end
        elsif k1_mon < target
          mon_list[k] = k1_mon
          mon_list[k1] = target
          k = k1
        else
          break
        end
      end
    end
    write.puts(max_count)
    write.close
    exit!(0)
  end
  if pids.key?(pid)
    counts << pids[pid].gets.to_i
    pids[pid].close
  else
    pids[pid] = read
  end
end
Process.waitall.each do |pst|
  counts << pids[pst[0]].gets.to_i
end
puts counts.min
# puts (Time.now - start_time)
0