結果
問題 | No.2438 Double Least Square |
ユーザー | rikein12 |
提出日時 | 2023-08-18 22:47:15 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,410 bytes |
コンパイル時間 | 392 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 129,764 KB |
最終ジャッジ日時 | 2024-11-28 09:01:35 |
合計ジャッジ時間 | 39,794 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,074 ms
127,056 KB |
testcase_01 | AC | 1,065 ms
126,428 KB |
testcase_02 | AC | 1,060 ms
126,288 KB |
testcase_03 | AC | 1,102 ms
127,192 KB |
testcase_04 | AC | 1,096 ms
126,932 KB |
testcase_05 | AC | 1,097 ms
126,808 KB |
testcase_06 | AC | 1,081 ms
127,184 KB |
testcase_07 | AC | 1,142 ms
126,160 KB |
testcase_08 | AC | 1,098 ms
126,804 KB |
testcase_09 | AC | 1,081 ms
126,676 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 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 1,088 ms
126,556 KB |
testcase_31 | AC | 1,081 ms
127,320 KB |
testcase_32 | WA | - |
ソースコード
import random N = int(input()) H = int(input()) X = [] for i in range(N): x,y = list(map(int,input().split())) X.append((x,y)) ans = 10**18 def calc(coef, xp, yp): a2 = yp/(xp+1e-9) a1 = (yp-H)/(xp+1e-9) return coef[0] + a1*coef[1] + (a1*a1)*coef[2] +\ a2*coef[3] + (a2*a2)*coef[4] coef1 = [[[0]*3 for j in range(501)] for i in range(501)] coef2 = [[[0]*3 for j in range(501)] for i in range(501)] for x,y in X: coef1[x][y][0] += ((y - H)**2) coef1[x][y][1] += (- 2*x*(y - H)) coef1[x][y][2] += (x**2) coef2[x][y][0] += y**2 coef2[x][y][1] += - 2*x*y coef2[x][y][2] += x**2 for x in range(501): for y in range(501): for i in range(3): if x>=1 and y>=1: coef1[x][y][i] += coef1[x-1][y][i] + coef1[x][y-1][i] - coef1[x-1][y-1][i] coef2[x][y][i] += coef2[x-1][y][i] + coef2[x][y-1][i] - coef2[x-1][y-1][i] elif x==0 and y>=1: coef1[x][y][i] += coef1[x][y-1][i] coef2[x][y][i] += coef2[x][y-1][i] elif y==0 and x>=1: coef1[x][y][i] += coef1[x-1][y][i] coef2[x][y][i] += coef2[x-1][y][i] for xp in range(501): for yp in range(501): coef = [0]*5 coef[0] += coef2[500][500][0] - coef2[500][yp][0] - coef2[xp][500][0] + 2*coef2[xp][yp][0] coef[3] += coef2[500][500][1] - coef2[500][yp][1] - coef2[xp][500][1] + 2*coef2[xp][yp][1] coef[4] += coef2[500][500][2] - coef2[500][yp][2] - coef2[xp][500][2] + 2*coef2[xp][yp][2] coef[0] += coef1[500][yp][0] + coef1[xp][500][0] - 2*coef1[xp][yp][0] coef[1] += coef1[500][yp][1] + coef1[xp][500][1] - 2*coef1[xp][yp][1] coef[2] += coef1[500][yp][2] + coef1[xp][500][2] - 2*coef1[xp][yp][2] ans = min(calc(coef, xp, yp), ans) ans = min(calc(coef, xp, yp+1), ans) ans = min(calc(coef, xp+1, yp), ans) ans = min(calc(coef, xp+1, yp+1), ans) for i in range(50): ans = min(calc(coef, xp + random.uniform(0,1), yp + random.uniform(0, 1)), ans) if abs(- coef[3]/(2*(coef[4]+1e-9)) + coef[1]/(2*(coef[2]+1e-9))) > 1e-9: xtest = H/(- coef[3]/(2*(coef[4]+1e-9)) + coef[1]/(2*(coef[2]+1e-9))) ytest = xtest * (- coef[3]/(2*(coef[4]+1e-9))) ans = min(calc(coef, min(max(xtest,xp),xp+1), min(max(ytest,yp),yp+1)), ans) print(ans)