Problem:
Closest Pair

For given n points in metric space, find the distance of the closest points.

Input

n
x0 y0
x1 y1
:
xn-1 yn-1

The first integer n is the number of points.

In the following n lines, the coordinate of the i-th point is given by two real numbers xi and yi. Each value is a real number with at most 6 digits after the decimal point.

Output

Print the distance in a line. The output values should be in a decimal fraction with an error less than 0.000001.

Constraints

2 ≤ n ≤ 100,000

-100 ≤ x, y ≤ 100

Sample Input 1

2
0.0 0.0
1.0 0.0

Sample Output 1

1.000000

Sample Input 2

3
0.0 0.0
2.0 0.0
1.0 1.0

Sample Output 2

1.41421356237

Solution in C++14 (judge verdict: Time Limit Exceeded)

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>

using namespace std;
using P = pair<double, double>;

int main() {

    int n;
    cin >> n;

    P p[n];

    for (int i = 0; i < n; i++) {
        double x, y;
        cin >> x >> y;
        p[i] = make_pair(x, y);
    }

    sort(p, p + n);

    double ans = 100000;

    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            P p1, p2;
            p1 = p[i];
            p2 = p[j];
            double dx, dy;
            dx = (p1.first - p2.first) * (p1.first - p2.first);
            dy = (p1.second - p2.second) * (p1.second - p2.second);
            if (dx > ans) break;
            ans = min(ans, dx + dy);
        }
    }

    cout << fixed << setprecision(7) << sqrt(ans) << endl;
}