結果
問題 | No.2438 Double Least Square |
ユーザー | chineristAC |
提出日時 | 2023-08-19 01:00:08 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,590 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 82,764 KB |
実行使用メモリ | 78,188 KB |
最終ジャッジ日時 | 2024-05-06 08:05:31 |
合計ジャッジ時間 | 6,206 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
55,040 KB |
testcase_01 | AC | 47 ms
55,040 KB |
testcase_02 | AC | 41 ms
55,424 KB |
testcase_03 | AC | 43 ms
55,040 KB |
testcase_04 | AC | 42 ms
54,784 KB |
testcase_05 | AC | 43 ms
55,040 KB |
testcase_06 | AC | 44 ms
54,912 KB |
testcase_07 | AC | 47 ms
54,912 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
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 | AC | 201 ms
77,608 KB |
testcase_21 | AC | 200 ms
77,864 KB |
testcase_22 | AC | 192 ms
77,800 KB |
testcase_23 | AC | 207 ms
77,604 KB |
testcase_24 | AC | 212 ms
77,760 KB |
testcase_25 | AC | 192 ms
77,712 KB |
testcase_26 | AC | 204 ms
77,844 KB |
testcase_27 | AC | 212 ms
77,740 KB |
testcase_28 | AC | 211 ms
77,880 KB |
testcase_29 | AC | 210 ms
77,860 KB |
testcase_30 | AC | 44 ms
55,168 KB |
testcase_31 | AC | 43 ms
54,784 KB |
testcase_32 | AC | 43 ms
54,912 KB |
ソースコード
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()) def solve(N,H,point): 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)])) ans = min(ans,calc([idx[j] for j in range(i+1)],[idx[j] for j in range(i+1,N)])) return ans def brute(N,H,point): 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 ans = 10**100 for S in range(1<<N): f = [i for i in range(N) if S>>i & 1] g = [i for i in range(N) if S>>i & 1 == 0] ans = min(ans,calc(f,g)) return ans import random while False: N = random.randint(3,10) H = random.randint(1,10) point = [] for i in range(N): x,y = [random.randint(1,10) for _ in range(2)] point.append((x,y)) N,H = 3,5 point = [(7,5),(8,7),(8,2)] res = solve(N,H,point) exp = brute(N,H,point) if abs(res-exp) > 10**-2: print("WA") print(N) print(H) for x,y in point: print(x,y) print("res:",res) print("exp:",exp) exit() else: print("AC") N = int(input()) H = int(input()) point = [tuple(mi()) for i in range(N)] print(solve(N,H,point))