結果
| 問題 | No.1251 絶対に間違ってはいけない最小化問題 |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2022-08-05 13:18:24 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 533 bytes |
| 記録 | |
| コンパイル時間 | 185 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 39,552 KB |
| 最終ジャッジ日時 | 2024-09-15 09:04:16 |
| 合計ジャッジ時間 | 10,061 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | WA * 15 TLE * 1 -- * 26 |
コンパイルメッセージ
Syntax OK
ソースコード
def ternary_search_tree(left, right)
loop_cnt = 10000
loop_cnt.times do
if yield((left * 2 + right) / 3.0) < yield((left + right * 2) / 3.0)
right = (left + right * 2) / 3.0
else
left = (left * 2 + right) / 3.0
end
end
(left + right) / 2.0
end
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
def f(x)
sum = 0
N.times do |i|
sum += B[i] * (x - A[i]).abs
end
sum
end
res = ternary_search_tree(-1 * 10 ** 7, 10 ** 7) { |x| f(x) }
puts [res, f(res).to_i].join(' ')
siman