Task: | Closest points |
Sender: | aalto2024k_002 |
Submission time: | 2024-11-13 17:00:29 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | RUNTIME ERROR | 0.39 s | details |
#2 | RUNTIME ERROR | 0.52 s | details |
#3 | RUNTIME ERROR | 0.59 s | details |
#4 | RUNTIME ERROR | 0.55 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | RUNTIME ERROR | 0.50 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | WRONG ANSWER | 0.00 s | details |
#10 | RUNTIME ERROR | 0.49 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | WRONG ANSWER | 0.01 s | details |
#13 | RUNTIME ERROR | 0.49 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | RUNTIME ERROR | 0.39 s | details |
#16 | RUNTIME ERROR | 0.50 s | details |
#17 | RUNTIME ERROR | 0.50 s | details |
#18 | WRONG ANSWER | 0.00 s | details |
Code
#include <bits/stdc++.h> using namespace std; long long distance(pair<long long, long long> p1, pair<long long, long long> p2) { return (p1.first - p2.first)*(p1.first - p2.first) + (p1.second - p2.second)*(p1.second - p2.second); } bool comparison(pair<long long, long long> a, pair<long long, long long> b) { return a.second < b.second; } long long solve_rec(vector<pair<long long, long long>> &points, int begin, int end) { if (end - begin == 2) { return distance(points[begin], points[begin+1]); } else if (points.size() == 3) { return min( distance(points[begin], points[begin+1]), min( distance(points[begin+1], points[begin+2]), distance(points[begin], points[begin+2]) ) ); } long long N = (end - begin); long long M = begin + N / 2; long long left = solve_rec(points, begin, M); long long right = solve_rec(points, M, end); long long d = min(left, right); vector<pair<long long, long long>> around; for (int i = 0; i < N; i++) { if (abs(points[begin+i].first - points[M].first) < d) { around.push_back(points[begin+i]); } } sort(around.begin(), around.end(), comparison); int size = (int) around.size(); for (int i = 0; i < size; ++i) { for (int j = i+1; j < size && (around[j].second - around[i].second) < d; j++) { long long dist = distance(around[i], around[j]); if (dist < d) d = dist; } } return d; } float solve(vector<pair<long long, long long>> &points) { return solve_rec(points, 0, points.size()); } int main() { int n; cin >> n; vector<pair<long long, long long>> points(n); for (int i = 0; i < n; i++) cin >> points[i].first >> points[i].second; sort(points.begin(), points.end()); cout << solve(points) << endl; }
Test details
Test 1
Verdict: RUNTIME ERROR
input |
---|
100 58 36 81 -7 46 49 87 -58 ... |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 2
Verdict: RUNTIME ERROR
input |
---|
200000 -222 -705 277 680 -436 561 528 -516 ... |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 3
Verdict: RUNTIME ERROR
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) |
Test 5
Verdict: ACCEPTED
input |
---|
4 0 0 0 3 3 0 1 1 |
correct output |
---|
2 |
user output |
---|
2 |
Test 6
Verdict: RUNTIME ERROR
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: WRONG ANSWER
input |
---|
2 -999999999 -999999999 999999999 999999999 |
correct output |
---|
7999999984000000008 |
user output |
---|
8e+18 |
Test 10
Verdict: RUNTIME ERROR
input |
---|
200000 0 1 1 1 2 1 3 1 ... |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 11
Verdict: ACCEPTED
input |
---|
8 1 10000 -1 -10000 2 0 -2 0 ... |
correct output |
---|
16 |
user output |
---|
16 |
Test 12
Verdict: WRONG ANSWER
input |
---|
3 -1000000000 -1000000000 1000000000 1000000000 0 0 |
correct output |
---|
2000000000000000000 |
user output |
---|
2e+18 |
Test 13
Verdict: RUNTIME ERROR
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) |
Test 16
Verdict: RUNTIME ERROR
input |
---|
200000 1 0 1 2 1 4 1 6 ... |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 17
Verdict: RUNTIME ERROR
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 |
---|
4e+18 |