Cod sursa(job #2733358)

Utilizator MocalinnoMoca Andrei Catalin Mocalinno Data 30 martie 2021 11:58:26
Problema Cele mai apropiate puncte din plan Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.28 kb
#include <bits/stdc++.h>
using namespace std;
void DAU(const string& task = "") {
    if (!task.empty())
        freopen((task + ".in").c_str(), "r", stdin),
        freopen((task + ".out").c_str(), "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
void PLEC() {
    exit(0);
}
#define int long long
#define x   first
#define y   second
#define PII pair<int, int>
inline double Dist(const PII& a, const PII& b) {
    return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + 1.0 * (a.y - b.y) * (a.y - b.y));
}
int n;
set<PII> s;
vector<PII> v;
double res(1e18);
signed main() {
    DAU("cmap");
    cin >> n;
    v.resize(n);
    for (PII& P : v)
        cin >> P.x >> P.y;
    sort(v.begin(), v.end());
    int i(0);
    for (int j = 0; j < n; ++j) {
        while (v[j].x - v[i].x >= res)
            s.erase({v[i].y, v[i].x}), ++i;
        auto st = s.lower_bound({v[j].y - static_cast<int>(res) - 1, 2e9});
        auto dr = s.lower_bound({v[j].y + static_cast<int>(res) + 1, 2e9});
        for (auto it = st; it != dr; ++it) {
            if (it == s.end()) break;
            res = min(res, Dist(v[j], {it -> y, it -> x}));
        }
        s.emplace(v[j].y, v[j].x);
    }
    cout << fixed << setprecision(10) << res;
    PLEC();
}