Task: | Closest points |
Sender: | aalto2024k_001 |
Submission time: | 2024-11-13 16:29:51 +0200 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.05 s | details |
#2 | TIME LIMIT EXCEEDED | -- | details |
#3 | TIME LIMIT EXCEEDED | -- | details |
#4 | TIME LIMIT EXCEEDED | -- | details |
#5 | WRONG ANSWER | 0.05 s | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
#7 | RUNTIME ERROR | 0.06 s | details |
#8 | RUNTIME ERROR | 0.07 s | details |
#9 | RUNTIME ERROR | 0.07 s | details |
#10 | ACCEPTED | 0.24 s | details |
#11 | ACCEPTED | 0.05 s | details |
#12 | RUNTIME ERROR | 0.06 s | details |
#13 | ACCEPTED | 0.24 s | details |
#14 | WRONG ANSWER | 0.05 s | details |
#15 | ACCEPTED | 0.06 s | details |
#16 | TIME LIMIT EXCEEDED | -- | details |
#17 | ACCEPTED | 0.25 s | details |
#18 | RUNTIME ERROR | 0.07 s | details |
Code
import sys import math from collections import deque input = sys.stdin.readline class Point: def __init__(self, x, y): self.x = x self.y = y def __sub__(self, other): return Point(self.x - other.x, self.y - other.y) def __eq__(self, other): return self.x == other.x and self.y == other.y def __lt__(self, other): return self.x < other.x or (self.x == other.x and self.y <= other.y) def cross_product(p, q): # x1y2 − x2y1 return p.x * q.y - p.y * q.x def dist(p1, p2): return (p1.x - p2.x)**2 + (p1.y - p2.y)**2 n = int(input()) points = [] for i in range(n): x, y = map(int, input().split()) points.append(Point(x, y)) points.sort() d = math.inf for i in range(1, n // 2): j = i - 1 dd = d ** 0.5 while j >= 0 and points[i].x - points[j].x < d: d = min(d, dist(points[i], points[j])) j -= 1 for i in range(n // 2, n): j = i - 1 dd = d ** 0.5 while j >= 0 and points[i].x - points[j].x < dd: d = min(d, dist(points[i], points[j])) j -= 1 k = n // 2 i = n // 2 dd = d ** 0.5 while k >= 0 and points[i].x - points[k].x < dd: k -= 1 i = n // 2 kk = n // 2 + 1 while kk < n and points[kk].x - points[i].x < dd: kk += 1 for i in range(k, kk + 1): for j in range(i + 1, kk + 1): d = min(d, dist(points[i], points[j])) print(d)
Test details
Test 1
Verdict: ACCEPTED
input |
---|
100 58 36 81 -7 46 49 87 -58 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 -222 -705 277 680 -436 561 528 -516 ... |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 -464738043 865360844 465231470 129093134 -276549869 -21946314 111055008 -48821736 ... |
correct output |
---|
25413170 |
user output |
---|
(empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 1 513001000 2 689002000 3 785003000 4 799004000 ... |
correct output |
---|
1000000 |
user output |
---|
(empty) |
Test 5
Verdict: WRONG ANSWER
input |
---|
4 0 0 0 3 3 0 1 1 |
correct output |
---|
2 |
user output |
---|
0 |
Test 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 1 0 1 1 1 2 1 3 ... |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 7
Verdict: RUNTIME ERROR
input |
---|
4 1 2 10 3 3 5 8 5 |
correct output |
---|
8 |
user output |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 68, in <module> d = min(d, dist(points[i], points[j])) IndexError: list index out of range
Test 8
Verdict: RUNTIME ERROR
input |
---|
4 10 6 4 10 8 3 2 3 |
correct output |
---|
13 |
user output |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 68, in <module> d = min(d, dist(points[i], points[j])) IndexError: list index out of range
Test 9
Verdict: RUNTIME ERROR
input |
---|
2 -999999999 -999999999 999999999 999999999 |
correct output |
---|
7999999984000000008 |
user output |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 68, in <module> d = min(d, dist(points[i], points[j])) IndexError: list index out of range
Test 10
Verdict: ACCEPTED
input |
---|
200000 0 1 1 1 2 1 3 1 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 11
Verdict: ACCEPTED
input |
---|
8 1 10000 -1 -10000 2 0 -2 0 ... |
correct output |
---|
16 |
user output |
---|
16 |
Test 12
Verdict: RUNTIME ERROR
input |
---|
3 -1000000000 -1000000000 1000000000 1000000000 0 0 |
correct output |
---|
2000000000000000000 |
user output |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 68, in <module> d = min(d, dist(points[i], points[j])) IndexError: list index out of range
Test 13
Verdict: ACCEPTED
input |
---|
199999 1 1 2 1 3 1 4 1 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 14
Verdict: WRONG ANSWER
input |
---|
4 0 0 5 8 6 1 10000 0 |
correct output |
---|
37 |
user output |
---|
0 |
Test 15
Verdict: ACCEPTED
input |
---|
435 -842 -199 -480 798 -176 -406 792 608 ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 16
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 1 0 1 2 1 4 1 6 ... |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 17
Verdict: ACCEPTED
input |
---|
200000 0 1 2 1 4 1 6 1 ... |
correct output |
---|
4 |
user output |
---|
4 |
Test 18
Verdict: RUNTIME ERROR
input |
---|
3 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000 |
correct output |
---|
4000000000000000000 |
user output |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 68, in <module> d = min(d, dist(points[i], points[j])) IndexError: list index out of range