結果

問題 No.9 モンスターのレベル上げ
ユーザー vjudge1
提出日時 2025-09-05 09:29:52
言語 Crystal
(1.14.0)
結果
WA  
実行時間 -
コード長 998 bytes
コンパイル時間 13,840 ms
コンパイル使用メモリ 315,308 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-05 09:30:13
合計ジャッジ時間 17,864 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

# Read n
n = gets.not_nil!.to_i

# Read array a (space-separated)
a = gets.not_nil!.split.map(&.to_i)

# Read array b (space-separated)  
b = gets.not_nil!.split.map(&.to_i)

ans = Int32::MAX

n.times do |i|
  t = 0
  # Use a min-heap simulation with a sorted array
  # Store pairs as [value, count] and keep sorted by value
  ta = a.map { |val| {val, 0} }.sort_by { |pair| pair[0] }
  
  n.times do |j|
    # Get the smallest element
    smallest = ta.shift
    value, count = smallest
    
    # Update the value (use proper integer division that truncates toward zero)
    addition = b[(i + j) % n]
    new_value = value + (addition > 0 ? addition // 2 : (addition - 1) // 2 + 1)
    new_count = count + 1
    
    # Track maximum count
    t = Math.max(t, new_count)
    
    # Find insertion position using binary search
    insert_index = ta.bsearch_index { |x| x[0] >= new_value } || ta.size
    ta.insert(insert_index, {new_value, new_count})
  end
  
  ans = Math.min(ans, t)
end

puts ans
0