Cod sursa(job #3308514)

Utilizator tibinyteCozma Tiberiu-Stefan tibinyte Data 25 august 2025 18:44:56
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 4.62 kb
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int random(int st, int dr)
{
    uniform_int_distribution<int> dist(st, dr);
    return dist(rng);
}

template <typename t>
using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = 998244353;
struct Mint
{
    int val;
    Mint(int x = 0)
    {
        val = x % mod;
    }
    Mint(long long x)
    {
        val = x % mod;
    }
    Mint operator+(Mint oth)
    {
        return val + oth.val;
    }
    Mint operator-(Mint oth)
    {
        return val - oth.val + mod;
    }
    Mint operator*(Mint oth)
    {
        return 1ll * val * oth.val;
    }
    void operator+=(Mint oth)
    {
        val = (*this + oth).val;
    }
    void operator-=(Mint oth)
    {
        val = (*this - oth).val;
    }
    void operator*=(Mint oth)
    {
        val = (*this * oth).val;
    }
};

Mint powmod(int a, int b)
{
    if (b == 0)
    {
        return 1;
    }
    if (b % 2 == 1)
    {
        return powmod(a, b - 1) * a;
    }
    Mint p = powmod(a, b / 2);
    return p * p;
}

/*
                 .___                 __                 __           .__
  ____  ____   __| _/____     _______/  |______ ________/  |_  ______ |  |__   ___________   ____
_/ ___\/  _ \ / __ |/ __ \   /  ___/\   __\__  \\_  __ \   __\/  ___/ |  |  \_/ __ \_  __ \_/ __ \
\  \__(  <_> ) /_/ \  ___/   \___ \  |  |  / __ \|  | \/|  |  \___ \  |   Y  \  ___/|  | \/\  ___/
 \___  >____/\____ |\___  > /____  > |__| (____  /__|   |__| /____  > |___|  /\___  >__|    \___  >
     \/           \/    \/       \/            \/                 \/       \/     \/            \/
*/

// #define cin fin
// #define cout fout
ifstream fin("cmap.in");
ofstream fout("cmap.out");

const ld inf = 1e18;
vector<pair<ld, ld>> a;

ld dist(pair<ld, ld> x, pair<ld, ld> y)
{
    return sqrtl((x.first - y.first) * (x.first - y.first) + (x.second - y.second) * (x.second - y.second));
}

struct events
{
    ld type;
    ld time;
    ld x, y;
    events(ld type, ld time, ld x, ld y) : type(type), time(time), x(x), y(y) {}
    bool operator<(events oth) const
    {
        return time < oth.time;
    }
};

ld divide(int st, int dr)
{
    if (st == dr)
    {
        return inf;
    }
    int mid = (st + dr) / 2;
    ld D = min(divide(st, mid), divide(mid + 1, dr));

    vector<pair<ld, ld>> filteredL, filteredR;

    ld split = a[mid].first;

    for (int i = st; i <= mid; ++i)
    {
        if (abs(a[i].first - split) <= D)
        {
            filteredL.push_back(a[i]);
        }
    }
    for (int i = mid + 1; i <= dr; ++i)
    {
        if (abs(a[i].first - split) <= D)
        {
            filteredR.push_back(a[i]);
        }
    }

    vector<events> E;

    for (auto [x, y] : filteredL)
    {
        E.push_back({1, y - D, x, y});
        E.push_back({2, y, x, y});
    }

    for (auto [x, y] : filteredR)
    {
        E.push_back({1, y - D, x, y});
        E.push_back({2, y, x, y});
    }

    sort(E.begin(), E.end());

    multiset<pair<int, int>> puncte;

    for (int i = 0; i < E.size(); ++i)
    {
        int type = E[i].type;
        if (type == 1)
        {
            puncte.insert({E[i].x, E[i].y});
        }
        if (type == 2)
        {
            puncte.erase(puncte.find({E[i].x, E[i].y}));
        }
        for (auto x : puncte)
        {
            for (auto y : puncte)
            {
                if (x.first != y.first || x.second != y.second)
                {
                    D = min(D, dist(x, y));
                }
            }
        }
    }

    return D;
}

int32_t main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    a.resize(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        int x, y;
        cin >> x >> y;
        a[i] = {x, y};
    }
    sort(a.begin() + 1, a.end());
    cout << fixed << setprecision(6) << divide(1, n) << '\n';
}
/*
I cannot take this anymore
Saying everything I've said before
All these words, they make no sense
I find bliss in ignorance
Less I hear, the less you say
You'll find that out anyway
Just like before

Everything you say to me
(Takes me one step closer to the edge)
(And I'm about to break)
I need a little room to breathe
(Cause I'm one step closer to the edge)
(I'm about to break)
*/