QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293910 | #5251. Constellations | LaStataleBlue# | WA | 0ms | 3564kb | C++20 | 2.4kb | 2023-12-29 22:52:09 | 2023-12-29 22:52:09 |
Judging History
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'