CSES - Aalto Competitive Programming 2024 - wk10 - Wed - Results
Submission details
Task:Closest points
Sender:aalto2024k_002
Submission time:2024-11-13 17:26:45 +0200
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.49 sdetails
#30.52 sdetails
#40.81 sdetails
#50.00 sdetails
#6--details
#70.00 sdetails
#80.00 sdetails
#90.00 sdetails
#100.42 sdetails
#110.01 sdetails
#120.00 sdetails
#130.43 sdetails
#140.00 sdetails
#150.01 sdetails
#16--details
#170.42 sdetails
#180.01 sdetails

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);
}

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());

    long long d = distance(points[0], points[1]);

    for (int i = 0; i < n; i++) {
        cout << points[i].first << " " << points[i].second << endl;
    }

    for (int i = 1; i < n; i++) {

        int j = i-1;

        while (j >= 0
            && abs(points[j].first - points[i].first)*abs(points[j].first - points[i].first) <= d) {

            if (abs(points[j].second - points[i].second)*abs(points[j].second - points[i].second) <= 2*d) {

                long long dist = distance(points[i], points[j]);
            
                if (dist < d) {
                    d = dist;
                }   

            }

            j -= 1; 

        }

    }

    cout << d << endl;

}

/*
8
105 0
100 0
2 0
-2 0
-100 0
-105 0
-1 -1000
1 1000
*/

Test details

Test 1

Verdict:

input
100
58 36
81 -7
46 49
87 -58
...

correct output
1

user output
-97 56
-96 -10
-90 -93
-89 -82
-88 91
...
Truncated

Test 2

Verdict:

input
200000
-222 -705
277 680
-436 561
528 -516
...

correct output
1

user output
-1000 -983
-1000 -973
-1000 -959
-1000 -948
-1000 -901
...
Truncated

Test 3

Verdict:

input
200000
-464738043 865360844
465231470 129093134
-276549869 -21946314
111055008 -48821736
...

correct output
25413170

user output
-999996669 934495384
-999988929 -448078121
-999970456 700089795
-999970148 -181956624
-999
...
Truncated

Test 4

Verdict:

input
200000
1 513001000
2 689002000
3 785003000
4 799004000
...

correct output
1000000

user output
1 513001000
2 689002000
3 785003000
4 799004000
5 554005000
...
Truncated

Test 5

Verdict:

input
4
0 0
0 3
3 0
1 1

correct output
2

user output
0 0
0 3
1 1
3 0
2

Test 6

Verdict:

input
200000
1 0
1 1
1 2
1 3
...

correct output
1

user output
(empty)

Test 7

Verdict:

input
4
1 2
10 3
3 5
8 5

correct output
8

user output
1 2
3 5
8 5
10 3
8

Test 8

Verdict:

input
4
10 6
4 10
8 3
2 3

correct output
13

user output
2 3
4 10
8 3
10 6
13

Test 9

Verdict:

input
2
-999999999 -999999999
999999999 999999999

correct output
7999999984000000008

user output
-999999999 -999999999
999999999 999999999
7999999984000000008

Test 10

Verdict:

input
200000
0 1
1 1
2 1
3 1
...

correct output
1

user output
0 1
1 1
2 1
3 1
4 1
...
Truncated

Test 11

Verdict:

input
8
1 10000
-1 -10000
2 0
-2 0
...

correct output
16

user output
-105 0
-100 0
-2 0
-1 -10000
1 10000
...

Test 12

Verdict:

input
3
-1000000000 -1000000000
1000000000 1000000000
0 0

correct output
2000000000000000000

user output
-1000000000 -1000000000
0 0
1000000000 1000000000
2000000000000000000

Test 13

Verdict:

input
199999
1 1
2 1
3 1
4 1
...

correct output
1

user output
1 1
2 1
3 1
4 1
5 1
...
Truncated

Test 14

Verdict:

input
4
0 0
5 8
6 1
10000 0

correct output
37

user output
0 0
5 8
6 1
10000 0
37

Test 15

Verdict:

input
435
-842 -199
-480 798
-176 -406
792 608
...

correct output
2

user output
-988 990
-984 -511
-979 856
-972 -90
-965 -473
...
Truncated

Test 16

Verdict:

input
200000
1 0
1 2
1 4
1 6
...

correct output
4

user output
(empty)

Test 17

Verdict:

input
200000
0 1
2 1
4 1
6 1
...

correct output
4

user output
0 1
2 1
4 1
6 1
8 1
...
Truncated

Test 18

Verdict:

input
3
-1000000000 -1000000000
1000000000 1000000000
1000000000 -1000000000

correct output
4000000000000000000

user output
-1000000000 -1000000000
1000000000 -1000000000
1000000000 1000000000
4000000000000000000