QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#293912 | #5251. Constellations | LaStataleBlue# | TL | 0ms | 3624kb | C++20 | 2.4kb | 2023-12-29 22:53:32 | 2023-12-29 22:53:33 |
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(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: 3624kb
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...