結果
| 問題 |
No.2438 Double Least Square
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 15:59:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,175 bytes |
| コンパイル時間 | 325 ms |
| コンパイル使用メモリ | 82,384 KB |
| 実行使用メモリ | 77,036 KB |
| 最終ジャッジ日時 | 2025-04-16 16:01:11 |
| 合計ジャッジ時間 | 3,391 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 11 |
ソースコード
n = int(input())
h = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]
a1 = 0.0
a2 = 0.0
prev_assignment = None
while True:
current_assignment = []
for x, y in points:
fx = a1 * x + h
gx = a2 * x
error_f = (y - fx) ** 2
error_g = (y - gx) ** 2
current_assignment.append(error_f <= error_g)
if current_assignment == prev_assignment:
break
prev_assignment = current_assignment.copy()
sum_f_x2 = 0.0
sum_f_xy = 0.0
sum_g_x2 = 0.0
sum_g_xy = 0.0
for i in range(n):
x, y = points[i]
if current_assignment[i]:
sum_f_x2 += x * x
sum_f_xy += x * (y - h)
else:
sum_g_x2 += x * x
sum_g_xy += x * y
new_a1 = a1
if sum_f_x2 != 0:
new_a1 = sum_f_xy / sum_f_x2
new_a2 = a2
if sum_g_x2 != 0:
new_a2 = sum_g_xy / sum_g_x2
a1 = new_a1
a2 = new_a2
total = 0.0
for x, y in points:
fx = a1 * x + h
gx = a2 * x
error_f = (y - fx) ** 2
error_g = (y - gx) ** 2
total += min(error_f, error_g)
print("{0:.20f}".format(total))
lam6er