結果

問題 No.9 モンスターのレベル上げ
ユーザー vjudge1
提出日時 2025-09-05 09:04:07
言語 Crystal
(1.14.0)
結果
TLE  
実行時間 -
コード長 849 bytes
コンパイル時間 13,801 ms
コンパイル使用メモリ 309,660 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-05 09:04:47
合計ジャッジ時間 36,520 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 2 TLE * 3 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

n = gets.not_nil!.to_i
a = gets.not_nil!.split.map(&.to_i)
b = gets.not_nil!.split.map(&.to_i)

# Create initial min-heap
heap = a.map { |val| {val, 0} }

ans = 10**9

n.times do |i|
  # Create a copy of the heap for this iteration
  temp_heap = heap.dup
  max_depth = 0
  
  n.times do |j|
    # Find the minimum element (simulate priority_queue.top() and pop())
    min_index = 0
    temp_heap.each_with_index do |(value, depth), idx|
      if value < temp_heap[min_index][0]
        min_index = idx
      end
    end
    
    # Remove the min element (pop())
    t, u = temp_heap.delete_at(min_index)
    
    # Add the new element (push())
    new_val = t + b[(i + j) % n] // 2
    new_depth = u + 1
    temp_heap << {new_val, new_depth}
    
    max_depth = Math.max(max_depth, new_depth)
  end
  
  ans = Math.min(ans, max_depth)
end

puts ans
0