結果
| 問題 |
No.1251 絶対に間違ってはいけない最小化問題
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2024-06-20 05:10:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 512 bytes |
| コンパイル時間 | 321 ms |
| コンパイル使用メモリ | 82,300 KB |
| 実行使用メモリ | 109,976 KB |
| 最終ジャッジ日時 | 2024-06-20 05:11:09 |
| 合計ジャッジ時間 | 19,796 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 21 |
ソースコード
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)
x = int(x + 0.5)
print(x, f(x))
norioc