| Task: | Closest points |
| Sender: | aalto25k_002 |
| Submission time: | 2025-11-12 17:18:10 +0200 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | RUNTIME ERROR |
| test | verdict | time | |
|---|---|---|---|
| #1 | RUNTIME ERROR | 0.07 s | details |
| #2 | TIME LIMIT EXCEEDED | -- | details |
| #3 | TIME LIMIT EXCEEDED | -- | details |
| #4 | RUNTIME ERROR | 0.79 s | details |
| #5 | ACCEPTED | 0.04 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | RUNTIME ERROR | 0.07 s | details |
| #8 | ACCEPTED | 0.04 s | details |
| #9 | ACCEPTED | 0.04 s | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | RUNTIME ERROR | 0.07 s | details |
| #12 | ACCEPTED | 0.05 s | details |
| #13 | TIME LIMIT EXCEEDED | -- | details |
| #14 | ACCEPTED | 0.04 s | details |
| #15 | RUNTIME ERROR | 0.07 s | details |
| #16 | TIME LIMIT EXCEEDED | -- | details |
| #17 | TIME LIMIT EXCEEDED | -- | details |
| #18 | ACCEPTED | 0.04 s | details |
Code
import math
def compareX(a, b):
p1, p2 = a, b
return (p1[0] != p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1])
def compareY(a, b):
p1, p2 = a, b
return (p1[1] != p2[1]) * (p1[1] - p2[1]) + (p1[0] - p2[0])
def dist(p1, p2):
return (p1[0] - p2[0])**2 + (p1[1] - p2[1])**2
def bruteForce(P, n):
min = float('inf')
for i in range(n):
for j in range(i+1, n):
if dist(P[i], P[j]) < min:
min = dist(P[i], P[j])
return min
def min(x, y):
return x if x < y else y
def stripClosest(strip, size, d):
min = d
for i in range(size):
for j in range(i+1, size):
if (strip[j][1] - strip[i][1]) < min:
if dist(strip[i],strip[j]) < min:
min = dist(strip[i], strip[j])
return min
def closestUtil(Px, Py, n):
if n <= 3:
return bruteForce(Px, n)
mid = n // 2
midPoint = Px[mid]
Pyl = [None] * mid
Pyr = [None] * (n-mid)
li = ri = 0
for i in range(n):
if ((Py[i][0] < midPoint[0] or (Py[i][0] == midPoint[0] and Py[i][1] < midPoint[1])) and li < mid):
Pyl[li] = Py[i]
li += 1
else:
Pyr[ri] = Py[i]
ri += 1
dl = closestUtil(Px, Pyl, mid)
dr = closestUtil(Px[mid:], Pyr, n-mid)
d = min(dl, dr)
strip = [None] * n
j = 0
for i in range(n):
if abs(Py[i][0] - midPoint[0]) < d:
strip[j] = Py[i]
j += 1
return stripClosest(strip, j, d)
def closest(P, n):
Px = P
Py = P
Px.sort(key=lambda x: x[0])
Py.sort(key=lambda x: x[1])
return closestUtil(Px, Py, n)
if __name__ == "__main__":
n = int(input())
points = []
for _ in range(n):
x, y = map(int, input().split())
points.append([x, y])
mec = closest(points, n)
print(mec)Test details
Test 1
Verdict: RUNTIME ERROR
| input |
|---|
| 100 58 36 81 -7 46 49 87 -58 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Error:
Traceback (most recent call last):
File "input/code.py", line 86, in <module>
mec = closest(points, n)
File "input/code.py", line 77, in closest
return closestUtil(Px, Py, n)
File "input/code.py", line 53, in closestUtil
Pyr[ri] = Py[i]
IndexError: list index out of rangeTest 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: RUNTIME ERROR
| input |
|---|
| 200000 1 513001000 2 689002000 3 785003000 4 799004000 ... |
| correct output |
|---|
| 1000000 |
| user output |
|---|
| (empty) |
Error:
Traceback (most recent call last):
File "input/code.py", line 86, in <module>
mec = closest(points, n)
File "input/code.py", line 77, in closest
return closestUtil(Px, Py, n)
File "input/code.py", line 53, in closestUtil
Pyr[ri] = Py[i]
IndexError: list index out of rangeTest 5
Verdict: ACCEPTED
| input |
|---|
| 4 0 0 0 3 3 0 1 1 |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
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 86, in <module>
mec = closest(points, n)
File "input/code.py", line 77, in closest
return closestUtil(Px, Py, n)
File "input/code.py", line 53, in closestUtil
Pyr[ri] = Py[i]
IndexError: list index out of rangeTest 8
Verdict: ACCEPTED
| input |
|---|
| 4 10 6 4 10 8 3 2 3 |
| correct output |
|---|
| 13 |
| user output |
|---|
| 13 |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 2 -999999999 -999999999 999999999 999999999 |
| correct output |
|---|
| 7999999984000000008 |
| user output |
|---|
| 7999999984000000008 |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 0 1 1 1 2 1 3 1 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Test 11
Verdict: RUNTIME ERROR
| input |
|---|
| 8 1 10000 -1 -10000 2 0 -2 0 ... |
| correct output |
|---|
| 16 |
| user output |
|---|
| (empty) |
Error:
Traceback (most recent call last):
File "input/code.py", line 86, in <module>
mec = closest(points, n)
File "input/code.py", line 77, in closest
return closestUtil(Px, Py, n)
File "input/code.py", line 57, in closestUtil
dl = closestUtil(Px, Pyl, mid)
File "input/code.py", line 53, in closestUtil
Pyr[ri] = Py[i]
IndexError: list index out of rangeTest 12
Verdict: ACCEPTED
| input |
|---|
| 3 -1000000000 -1000000000 1000000000 1000000000 0 0 |
| correct output |
|---|
| 2000000000000000000 |
| user output |
|---|
| 2000000000000000000 |
Test 13
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 199999 1 1 2 1 3 1 4 1 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Test 14
Verdict: ACCEPTED
| input |
|---|
| 4 0 0 5 8 6 1 10000 0 |
| correct output |
|---|
| 37 |
| user output |
|---|
| 37 |
Test 15
Verdict: RUNTIME ERROR
| input |
|---|
| 435 -842 -199 -480 798 -176 -406 792 608 ... |
| correct output |
|---|
| 2 |
| user output |
|---|
| (empty) |
Error:
Traceback (most recent call last):
File "input/code.py", line 86, in <module>
mec = closest(points, n)
File "input/code.py", line 77, in closest
return closestUtil(Px, Py, n)
File "input/code.py", line 57, in closestUtil
dl = closestUtil(Px, Pyl, mid)
File "input/code.py", line 57, in closestUtil
dl = closestUtil(Px, Pyl, mid)
File "input/code.py", line 53, in closestUtil
Pyr[ri] = Py[i]
IndexError: list index out of rangeTest 16
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 1 0 1 2 1 4 1 6 ... |
| correct output |
|---|
| 4 |
| user output |
|---|
| (empty) |
Test 17
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 0 1 2 1 4 1 6 1 ... |
| correct output |
|---|
| 4 |
| user output |
|---|
| (empty) |
Test 18
Verdict: ACCEPTED
| input |
|---|
| 3 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000 |
| correct output |
|---|
| 4000000000000000000 |
| user output |
|---|
| 4000000000000000000 |
