| Task: | Closest points |
| Sender: | hy2025_002 |
| Submission time: | 2025-11-12 17:51:01 +0200 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.05 s | details |
| #2 | TIME LIMIT EXCEEDED | -- | details |
| #3 | TIME LIMIT EXCEEDED | -- | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | WRONG ANSWER | 0.04 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | ACCEPTED | 0.04 s | details |
| #8 | WRONG ANSWER | 0.04 s | details |
| #9 | ACCEPTED | 0.04 s | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | WRONG ANSWER | 0.04 s | details |
| #12 | ACCEPTED | 0.04 s | details |
| #13 | TIME LIMIT EXCEEDED | -- | details |
| #14 | WRONG ANSWER | 0.04 s | details |
| #15 | WRONG ANSWER | 0.08 s | details |
| #16 | TIME LIMIT EXCEEDED | -- | details |
| #17 | TIME LIMIT EXCEEDED | -- | details |
| #18 | WRONG ANSWER | 0.04 s | details |
Code
import math
from bisect import bisect_left, bisect_right, insort
def closest_pair(points, n):
points.sort(key=lambda p: (p[0], p[1]))
active = []
best_sq = float('inf')
left = 0
for i in range(n):
x, i = points[i]
D = math.isqrt(int(best_sq)) + 1 if best_sq != float('inf') else float('inf')
while left < i and x - points[left][0] >= D:
tup = (points[left][1], points[left][0])
pos = bisect_left(active, tup)
if pos < len(active) and active[pos] == tup:
del active[pos]
left +=1
lo = bisect_left(active, (y - D, -math.inf))
hi = bisect_right(active, (y + D, math.inf))
for yj, xj in active[lo:hi]:
dx = x - xj
dy = y - yj
d2 = dx * dx + dy * dy
if d2 < best_sq:
best_sq = d2
insort(active, (y,x))
return int(best_sq)
if __name__ == "__main__":
n = int(input())
points = []
for _ in range(n):
(x,y) = map(int, input().split())
points.append((x,y))
print(closest_pair(points, n)*2)
Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 100 58 36 81 -7 46 49 87 -58 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 0 |
Feedback: Incorrect character on line 1 col 1: expected "1", got "0"
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 |
Feedback: Incorrect character on line 1 col 1: expected "2", got "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: ACCEPTED
| input |
|---|
| 4 1 2 10 3 3 5 8 5 |
| correct output |
|---|
| 8 |
| user output |
|---|
| 8 |
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 4 10 6 4 10 8 3 2 3 |
| correct output |
|---|
| 13 |
| user output |
|---|
| 8 |
Feedback: Incorrect character on line 1 col 1: expected "13", got "8"
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: WRONG ANSWER
| input |
|---|
| 8 1 10000 -1 -10000 2 0 -2 0 ... |
| correct output |
|---|
| 16 |
| user output |
|---|
| 2 |
Feedback: Incorrect character on line 1 col 1: expected "16", got "2"
Test 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: WRONG ANSWER
| input |
|---|
| 4 0 0 5 8 6 1 10000 0 |
| correct output |
|---|
| 37 |
| user output |
|---|
| 2 |
Feedback: Incorrect character on line 1 col 1: expected "37", got "2"
Test 15
Verdict: WRONG ANSWER
| input |
|---|
| 435 -842 -199 -480 798 -176 -406 792 608 ... |
| correct output |
|---|
| 2 |
| user output |
|---|
| 0 |
Feedback: Incorrect character on line 1 col 1: expected "2", got "0"
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: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 0 1 2 1 4 1 6 1 ... |
| correct output |
|---|
| 4 |
| user output |
|---|
| (empty) |
Test 18
Verdict: WRONG ANSWER
| input |
|---|
| 3 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000 |
| correct output |
|---|
| 4000000000000000000 |
| user output |
|---|
| 0 |
Feedback: Incorrect character on line 1 col 1: expected "400000000000...", got "0"
