結果

問題 No.9 モンスターのレベル上げ
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2015-01-27 21:44:34
言語 Ruby
(3.3.0)
結果
AC  
実行時間 3,397 ms / 5,000 ms
コード長 1,440 bytes
コンパイル時間 55 ms
コンパイル使用メモリ 11,560 KB
実行使用メモリ 31,940 KB
最終ジャッジ日時 2023-09-06 03:25:50
合計ジャッジ時間 30,174 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,320 KB
testcase_01 AC 87 ms
15,072 KB
testcase_02 AC 3,192 ms
31,860 KB
testcase_03 AC 2,498 ms
29,132 KB
testcase_04 AC 1,332 ms
22,796 KB
testcase_05 AC 903 ms
20,516 KB
testcase_06 AC 359 ms
17,076 KB
testcase_07 AC 85 ms
15,120 KB
testcase_08 AC 459 ms
17,680 KB
testcase_09 AC 3,088 ms
31,940 KB
testcase_10 AC 83 ms
15,320 KB
testcase_11 AC 3,397 ms
31,916 KB
testcase_12 AC 694 ms
31,704 KB
testcase_13 AC 3,071 ms
31,908 KB
testcase_14 AC 3,071 ms
31,748 KB
testcase_15 AC 2,847 ms
30,996 KB
testcase_16 AC 124 ms
15,596 KB
testcase_17 AC 1,876 ms
25,432 KB
testcase_18 AC 1,533 ms
23,856 KB
testcase_19 AC 108 ms
15,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
n0 = 11
n1 = 2 ** n0
own_list = gets.split.map(&:to_i)
exp_list = gets.split.map{|s|s.to_i / 2}
org_mon_list = [0]
own_list.each do |level|
  point = level << 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)
low_count = 1500
n.times do |i|
  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
  low_count = max_count if max_count < low_count
end
puts low_count
0