結果
| 問題 | 
                            No.2438 Double Least Square
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-08-18 21:58:11 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 783 bytes | 
| コンパイル時間 | 478 ms | 
| コンパイル使用メモリ | 81,792 KB | 
| 実行使用メモリ | 89,088 KB | 
| 最終ジャッジ日時 | 2024-11-28 07:00:11 | 
| 合計ジャッジ時間 | 103,912 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | TLE * 3 | 
| other | TLE * 30 | 
ソースコード
import random
N = int(input())
H = int(input())
X = [list(map(int,input().split())) for i in range(N)]
ans = 10**18
def calc(coef, xp, yp):
    a2 = yp/xp
    a1 = (yp-H)/xp
    return coef[0] + a1*coef[1] + (a1*a1)*coef[2] +\
        a2*coef[3] + (a2*a2)*coef[4]
for xp in range(501):
    for yp in range(501):
        coef = [0]*5
        for x, y in X:
            if (x <= xp and y <= yp) or (x > xp and y > yp):
                coef[0] += y**2
                coef[3] += - 2*x*y
                coef[4] += x**2
            else:
                coef[0] += (y - H)**2
                coef[1] += - 2*x*(y - H)
                coef[2] += x**2
        for i in range(1000):
            ans = min(calc(coef, xp + random.uniform(0,1), yp + random.uniform(0, 1)), ans)
print(ans)