結果
問題 |
No.9 モンスターのレベル上げ
|
ユーザー |
![]() |
提出日時 | 2025-09-05 09:28:32 |
言語 | Crystal (1.14.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 828 bytes |
コンパイル時間 | 13,352 ms |
コンパイル使用メモリ | 315,124 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-05 09:28:51 |
合計ジャッジ時間 | 19,462 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 WA * 5 |
ソースコード
# 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 # Create a min-heap using an array sorted by first element ta = a.map { |val| {val, 0} }.sort_by { |pair| pair[0] } n.times do |j| # Get the smallest element (first in sorted array) p = ta.shift # Update the value and count new_val = p[0] + b[(i + j) % n] // 2 new_count = p[1] + 1 # Keep track of maximum count t = Math.max(t, new_count) # Insert back into sorted position using bsearch insert_index = ta.bsearch_index { |x| x[0] >= new_val } || ta.size ta.insert(insert_index, {new_val, new_count}) end ans = Math.min(ans, t) end puts ans