結果

問題 No.2438 Double Least Square
ユーザー kuronikuroni
提出日時 2023-08-18 23:02:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 349 bytes
コンパイル時間 464 ms
コンパイル使用メモリ 10,740 KB
実行使用メモリ 95,920 KB
最終ジャッジ日時 2023-08-18 23:02:26
合計ジャッジ時間 7,749 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 316 ms
56,872 KB
testcase_02 AC 329 ms
58,328 KB
testcase_03 AC 322 ms
56,800 KB
testcase_04 WA -
testcase_05 AC 322 ms
56,900 KB
testcase_06 AC 350 ms
56,752 KB
testcase_07 AC 341 ms
56,620 KB
testcase_08 AC 321 ms
57,132 KB
testcase_09 AC 363 ms
57,852 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 601 ms
56,860 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 608 ms
57,088 KB
testcase_25 AC 556 ms
58,204 KB
testcase_26 AC 589 ms
57,852 KB
testcase_27 AC 706 ms
58,136 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 315 ms
57,728 KB
testcase_31 AC 346 ms
56,640 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from scipy.optimize import minimize

n = int(input())
h = int(input())
points = [tuple(map(int, input().split())) for i in range(n)]

def f(params):
    a1, a2 = params
    ret = 0
    for x, y in points:
        ret += min((y - (a1 * x + h)) ** 2, (y - a2 * x) ** 2)
    return ret

print(minimize(f, (0, 0), args=(), method='BFGS', tol=1e-9).fun)
0