QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#293910#5251. ConstellationsLaStataleBlue#WA 0ms3564kbC++202.4kb2023-12-29 22:52:092023-12-29 22:52:09

Judging History

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

  • [2023-12-29 22:52:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3564kb
  • [2023-12-29 22:52:09]
  • 提交

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;

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<ll, int>>> stars;

static ll 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])
    );
}

static void update_dist(int a) {
    auto &d = stars[a];
    for (auto [b, _]: stars) {
        if (a == b) continue;
        ll w = dist(a, b);
        d.emplace(w, b);
        stars[b].emplace(w, 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++) {
        update_dist(a);
    }

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

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

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

        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];

        for (auto [d, i] : stars[old]) {
            stars[i].erase({d, old});
        }
        for (auto [d, i] : stars[young]) {
            stars[i].erase({d, young});
        }

        stars.erase(old);
        stars.erase(young);

        update_dist(t);

        ans.push_back(old);
    }

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

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3564kb

input:

2
0 0
1 0

output:

0

result:

wrong answer 1st lines differ - expected: '2', found: '0'