結果
問題 |
No.2438 Double Least Square
|
ユーザー |
|
提出日時 | 2023-08-19 00:51:04 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,026 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 78,048 KB |
最終ジャッジ日時 | 2024-11-28 13:03:18 |
合計ジャッジ時間 | 4,177 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 12 |
ソースコード
import sys from itertools import permutations from heapq import * from math import acos input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) N = int(input()) H = int(input()) point = [tuple(mi()) for i in range(N)] def calc(f,g): res = 0 a,b,c = 0,0,0 for i in f: x,y = point[i] a += x*x b += 2*x*(H-y) c += (H-y)*(H-y) if a!=0: t = (-b/(2*a)) res += a * t * t + b * t + c a,b,c = 0,0,0 for i in g: x,y = point[i] a += x*x b += 2 * x * y c += y*y if a!=0: t = (-b/(2*a)) res += a * t * t + b * t + c return res arg = [] for i in range(N): x,y = point[i] r = ((y-H/2)**2 + x**2)**.5 arg.append(acos((H/2-y)/r)) idx = [i for i in range(N)] idx.sort(key=lambda i:arg[i]) ans = calc([i for i in range(N)],[]) for i in range(N): ans = min(ans,calc([idx[j] for j in range(i+1,N)],[idx[j] for j in range(i+1)])) print(ans)