QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90313 | #5251. Constellations | chiranko# | WA | 1703ms | 151048kb | C++11 | 2.5kb | 2023-03-22 17:32:14 | 2023-03-22 17:32:15 |
Judging History
answer
#include <bits/stdc++.h>
#include <random>
#define MP make_pair
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const int maxn = 2005;
int merge_time[maxn];
LL dist[maxn][maxn];
LL sumx[maxn][2], sumy[maxn][2], siz[maxn];
struct star{
LL value;
int id1, id2;
bool operator < (const star b)const{
if(value * siz[b.id1] * siz[b.id2] != b.value * siz[id1] * siz[id2])
return value * siz[b.id1] * siz[b.id2] < b.value * siz[id1] * siz[id2];
if(min(merge_time[id1], merge_time[id2]) != min(merge_time[b.id1], merge_time[b.id2]))
return min(merge_time[id1], merge_time[id2]) < min(merge_time[b.id1], merge_time[b.id2]);
return max(merge_time[id1], merge_time[id2]) < max(merge_time[b.id1], merge_time[b.id2]);
}
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
set<star> st;
for(int i = 1; i <= n; ++i){
cin >> sumx[i][0] >> sumy[i][0];
sumx[i][1] = sumx[i][0] * sumx[i][0];
sumy[i][1] = sumy[i][0] * sumy[i][0];
siz[i] = 1;
merge_time[i] = i;
}
auto calc_dist = [&](int i, int j) -> LL{
auto _x = sumx[i][1] * siz[j] + sumx[j][1] * siz[i] - 2 * sumx[i][0] * sumx[j][0];
auto _y = sumy[i][1] * siz[j] + sumy[j][1] * siz[i] - 2 * sumy[i][0] * sumy[j][0];
return 1.0 * (_x + _y);
};
auto rem = [&](int i, int j) -> void{
if(!siz[i] || !siz[j] || i == j)
return;
int u = min(i, j), v = max(i, j);
st.erase({dist[u][v], u, v});
dist[u][v] = 0;
};
auto add = [&](int i, int j) -> void{
if(!siz[i] || !siz[j] || i == j)
return;
int u = min(i, j), v = max(i, j);
dist[u][v] = calc_dist(u, v);
st.insert({dist[u][v], u, v});
};
auto merge = [&](int i, int j, int now) -> void{
for(int k = 1; k <= n; ++k){
rem(i, k); rem(j, k);
}
siz[i] += siz[j];
siz[j] = 0;
sumx[i][0] += sumx[j][0]; sumx[i][1] += sumx[j][1];
sumy[i][0] += sumy[j][0]; sumy[i][1] += sumy[j][1];
sumy[i][0] = sumy[i][1] = sumx[i][0] = sumx[i][1] = 0;
dist[i][j] = 0;
merge_time[i] = now;
merge_time[j] = n * n;
for(int k = 1; k <= n; ++k){
add(i, k);
}
};
for(int i = 1; i <= n; ++i){
for(int j = i + 1; j <= n; ++j){
auto t = calc_dist(i, j);
dist[i][j] = t;
st.insert({dist[i][j], i, j});
}
}
for(int round = 1; round <= n - 1; ++round){
auto tp = *(st.begin());
st.erase(st.begin());
int u = tp.id1, v = tp.id2;
merge(u, v, n + round);
// cerr << "merge " << u << " " << v << endl;
cout << siz[u] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3320kb
input:
2 0 0 1 0
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 1703ms
memory: 151048kb
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:
2 2 4 2 6 2 8 2 10 2 12 2 14 2 16 2 18 2 20 2 22 2 24 2 26 2 28 2 30 2 32 2 34 2 36 2 38 2 40 2 42 2 44 2 46 2 48 2 50 2 52 2 54 2 56 2 58 2 60 2 62 2 64 2 66 2 68 2 70 2 72 2 74 2 76 2 78 2 80 2 82 2 84 2 86 2 88 2 90 2 92 2 94 2 96 2 98 2 100 2 102 2 104 2 106 2 108 2 110 2 112 2 114 2 116 2 118 2...
result:
wrong answer 3rd lines differ - expected: '2', found: '4'