| Task: | Closest points |
| Sender: | aalto25k_003 |
| Submission time: | 2025-11-12 17:33:15 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.00 s | details |
| #2 | ACCEPTED | 0.15 s | details |
| #3 | WRONG ANSWER | 1.00 s | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | ACCEPTED | 0.00 s | details |
| #8 | ACCEPTED | 0.00 s | details |
| #9 | ACCEPTED | 0.00 s | details |
| #10 | ACCEPTED | 0.13 s | details |
| #11 | ACCEPTED | 0.00 s | details |
| #12 | ACCEPTED | 0.00 s | details |
| #13 | ACCEPTED | 0.12 s | details |
| #14 | ACCEPTED | 0.00 s | details |
| #15 | ACCEPTED | 0.00 s | details |
| #16 | TIME LIMIT EXCEEDED | -- | details |
| #17 | ACCEPTED | 0.12 s | details |
| #18 | ACCEPTED | 0.00 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long C;
typedef complex<C> P;
#define X real()
#define Y imag()
/**
*
* import sys
n = int(input())
points = []
for _ in range(n):
x, y = map(int, input().split())
points.append((x, y))
def square_distance(x1, y1, x2, y2):
return (x1 - x2) ** 2 + (y1 - y2) ** 2
min_square_distance = sys.maxsize
points.sort(key=lambda p: p[0])
for i in range(n):
for j in range(i - 1, 0, -1):
if points[i][0] - min_square_distance <= points[j][0]:
square_dist = square_distance(points[j][0], points[j][1], points[i][0], points[i][1])
min_square_distance = min(min_square_distance, square_dist)
else:
break
print(min_square_distance)
*/
struct point {
long long x;
long long y;
};
long long d2(const point& a, const point& b) {
point ab = {a.x - b.x, a.y - b.y};
return ab.x*ab.x + ab.y*ab.y;
}
bool cmp(const point&a, const point&b) {
return a.x < b.x;
}
int main() {
int n;
cin >> n;
vector<point> points;
for(int i =0; i < n; i++) {
long long x, y;
cin >> x >> y;
points.push_back({x, y});
}
long long mind2 = LLONG_MAX;
sort(points.begin(), points.end(), cmp);
// for (const auto& point : points) {
// cout << point.x << ' ' << point.y << '\n';
// }
for(int i = 0; i < n; i++) {
for(int j = i-1; j >=0; j--) {
if(points[i].x - mind2 <= points[j].x) {
long long sd = d2(points[j], points[i]);
mind2 = min(mind2, sd);
}
else break;
}
}
cout << mind2 << '\n';
return 0;
}
/**
* for i in range(n):
for j in range(i - 1, 0, -1):
if points[i][0] - min_square_distance <= points[j][0]:
square_dist = square_distance(points[j][0], points[j][1], points[i][0], points[i][1])
min_square_distance = min(min_square_distance, square_dist)
else:
break
*/Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 100 58 36 81 -7 46 49 87 -58 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 10 |
Feedback: Incorrect character on line 1 col 2: expected "1", got "10"
Test 2
Verdict: ACCEPTED
| input |
|---|
| 200000 -222 -705 277 680 -436 561 528 -516 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 200000 -464738043 865360844 465231470 129093134 -276549869 -21946314 111055008 -48821736 ... |
| correct output |
|---|
| 25413170 |
| user output |
|---|
| 43558105 |
Feedback: Incorrect character on line 1 col 1: expected "25413170", got "43558105"
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: 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: ACCEPTED
| input |
|---|
| 4 1 2 10 3 3 5 8 5 |
| correct output |
|---|
| 8 |
| user output |
|---|
| 8 |
Test 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: 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: ACCEPTED
| input |
|---|
| 3 -1000000000 -1000000000 1000000000 1000000000 0 0 |
| correct output |
|---|
| 2000000000000000000 |
| user output |
|---|
| 2000000000000000000 |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 199999 1 1 2 1 3 1 4 1 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Test 14
Verdict: ACCEPTED
| input |
|---|
| 4 0 0 5 8 6 1 10000 0 |
| correct output |
|---|
| 37 |
| user output |
|---|
| 37 |
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: ACCEPTED
| input |
|---|
| 3 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000 |
| correct output |
|---|
| 4000000000000000000 |
| user output |
|---|
| 4000000000000000000 |
