QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90310 | #5251. Constellations | chiranko# | WA | 4648ms | 151336kb | C++11 | 2.4kb | 2023-03-22 17:23:35 | 2023-03-22 17:23:38 |
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;
using DB = double;
const int maxn = 2005;
int merge_time[maxn];
DB dist[maxn][maxn];
DB sumx[maxn][2], sumy[maxn][2], siz[maxn];
struct star{
DB value;
int id1, id2;
bool operator < (const star b)const{
if(value != b.value)
return value < b.value;
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 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});
};
auto add = [&](int i, int j) -> void{
if(!siz[i] || !siz[j] || i == j)
return;
int u = min(i, j), v = max(i, j);
st.insert({dist[u][v], u, v});
};
auto calc_dist = [&](int i, int j) -> DB{
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 (_x + _y) / siz[i] / siz[j];
};
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){
DB 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);
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: 3628kb
input:
2 0 0 1 0
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 2991ms
memory: 151336kb
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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 1999 lines
Test #3:
score: 0
Accepted
time: 2970ms
memory: 151268kb
input:
2000 -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 -971...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 1999 lines
Test #4:
score: 0
Accepted
time: 3054ms
memory: 151288kb
input:
2000 -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 -10...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 1999 lines
Test #5:
score: 0
Accepted
time: 3020ms
memory: 151252kb
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 -9...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 1999 lines
Test #6:
score: -100
Wrong Answer
time: 4648ms
memory: 151152kb
input:
2000 1000 -250 1000 -249 1000 -248 1000 -247 1000 -246 1000 -245 1000 -244 1000 -243 1000 -242 1000 -241 1000 -240 1000 -239 1000 -238 1000 -237 1000 -236 1000 -235 1000 -234 1000 -233 1000 -232 1000 -231 1000 -230 1000 -229 1000 -228 1000 -227 1000 -226 1000 -225 1000 -224 1000 -223 1000 -222 1000 ...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
wrong answer 1783rd lines differ - expected: '16', found: '20'