QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293908 | #5251. Constellations | LaStataleBlue# | TL | 1ms | 3600kb | C++20 | 2.2kb | 2023-12-29 22:47:12 | 2023-12-29 22:47:13 |
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 ll min_dist(int a) {
return stars[a].begin()->first;
}
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);
}
for (int t = N; stars.size() > 1; t++) {
int old = stars.begin()->first;
for (auto [i, _] : stars) {
if (min_dist(i) < min_dist(old)) {
old = i;
}
}
int young = stars[old].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);
cout << sz[t] << '\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: 100
Accepted
time: 1ms
memory: 3600kb
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...