QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293923#5251. ConstellationsLaStataleBlue#TL 0ms3444kbC++202.7kb2023-12-29 23:00:352023-12-29 23:00:36

Judging History

你现在查看的是最新测评结果

  • [2023-12-29 23:00:36]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3444kb
  • [2023-12-29 23:00:35]
  • 提交

answer

#pragma ide diagnostic ignored "misc-no-recursion"

#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
typedef long double db;

#define TESTCASE 0

static constexpr int MAX_N = 10'000;
static constexpr ll INF = 1e15;

struct frac {
    ll num, den;

    frac(ll num, ll den) : num(num), den(den) {}

    bool operator<(const frac &other) const {
        return num * other.den < other.num * den;
    }
};

static ll sum_sq[MAX_N];
static ll sum_x[MAX_N], sum_y[MAX_N];
static int sz[MAX_N];
static map<int, set<pair<frac, int>>> stars;

static frac dist(int a, int b) {
    return {
            sz[b] * sum_sq[a] + sz[a] * sum_sq[b] - 2 * (sum_x[a] * sum_x[b] + sum_y[a] * sum_y[b]),
            sz[a] * sz[b],
    };
}

static void create(int a) {
    auto &d = stars[a];
    for (auto [b, _]: stars) {
        if (a == b) continue;
        auto f = dist(a, b);
        d.emplace(f, b);
        stars[b].emplace(f, a);
    }
}

static void destroy(int a) {
    for (auto [d, i]: stars[a]) {
        stars[i].erase({d, a});
    }
    stars.erase(a);
}

static void solve([[maybe_unused]] int tc) {
    int N;
    cin >> N;

    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        sum_x[i] = x;
        sum_y[i] = y;
        sum_sq[i] = x * x + y * y;
        sz[i] = 1;
    }

    for (int a = 0; a < N; a++) {
        create(a);
    }

    vector<int> ans;
    ans.reserve(N);

    for (int t = N; stars.size() > 1; t++) {
        auto old_it = stars.begin();
        assert(!old_it->second.empty());
        
        auto old_dist = old_it->second.begin()->first;
        for (auto it = next(old_it); it != stars.end(); it++) {
            assert(!it->second.empty());
            auto f = it->second.begin()->first;
            if (f < old_dist) {
                old_it = it;
                old_dist = f;
            }
        }

        int old = old_it->first;
        int young = old_it->second.begin()->second;
        assert(old != young);

        sum_x[t] = sum_x[old] + sum_x[young];
        sum_y[t] = sum_y[old] + sum_y[young];
        sum_sq[t] = sum_sq[old] + sum_sq[young];
        sz[t] = sz[old] + sz[young];

        destroy(old);
        destroy(young);

        create(t);

        ans.push_back(sz[t]);
    }

    for (int a: ans) {
        cout << a << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);

    if (const char *f = getenv("REDIRECT_STDOUT"); f) {
        freopen(f, "w", stdout);
    }

    int T = 1;
#if TESTCASE
    cin >> T;
#endif

    for (int t = 1; t <= T; t++) {
        solve(t);
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3444kb

input:

2
0 0
1 0

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Time Limit Exceeded

input:

2000
1000 -1000
1000 -999
1000 -998
1000 -997
1000 -996
1000 -995
1000 -994
1000 -993
1000 -992
1000 -991
1000 -990
1000 -989
1000 -988
1000 -987
1000 -986
1000 -985
1000 -984
1000 -983
1000 -982
1000 -981
1000 -980
1000 -979
1000 -978
1000 -977
1000 -976
1000 -975
1000 -974
1000 -973
1000 -972
1000...

output:


result: