結果
| 問題 |
No.9 モンスターのレベル上げ
|
| ユーザー |
vjudge1
|
| 提出日時 | 2025-09-05 09:33:04 |
| 言語 | Crystal (1.14.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 823 bytes |
| コンパイル時間 | 11,908 ms |
| コンパイル使用メモリ | 311,816 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-09-05 09:33:20 |
| 合計ジャッジ時間 | 13,593 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 WA * 11 RE * 7 |
ソースコード
n = gets.not_nil!.to_i
a = gets.not_nil!.split.map(&.to_i)
b = gets.not_nil!.split.map(&.to_i)
max_result = 0
n.times do |i|
rotated_b = b.rotate(i)
heap = a.map { |v| v * n }.sort
min_count = Int32::MAX
rotated_b.each do |val|
# Get largest element (from the end)
encoded = heap.pop
current_value = encoded // n
current_count = encoded % n
# Update value
new_value = current_value + val // 2
new_count = current_count + 1
# Encode back
new_encoded = new_value * n + new_count
# Insert back using binary search
insert_index = heap.bsearch_index { |x| x >= new_encoded } || heap.size
heap.insert(insert_index, new_encoded)
min_count = Math.min(min_count, new_count)
end
max_result = Math.max(max_result, min_count)
end
puts max_result
vjudge1