結果
| 問題 |
No.1251 絶対に間違ってはいけない最小化問題
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2024-06-20 05:08:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 509 bytes |
| コンパイル時間 | 393 ms |
| コンパイル使用メモリ | 81,976 KB |
| 実行使用メモリ | 109,880 KB |
| 最終ジャッジ日時 | 2024-06-20 05:08:57 |
| 合計ジャッジ時間 | 19,251 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 42 |
ソースコード
def ternary_search(f, lo, hi) -> float:
l = lo
r = hi
for _ in range(100):
c1 = (l * 2 + r) / 3
c2 = (l + r * 2) / 3
if f(c1) > f(c2):
l = c1
else:
r = c2
return l
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def f(x):
res = 0
for a, b in zip(A, B):
res += b * abs(x - a)
return res
lo = min(A)
hi = max(A)
x = ternary_search(f, lo, hi)
print(f'{x:.5f} {f(x):.5f}')
norioc