QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90314 | #5251. Constellations | chiranko# | WA | 6040ms | 198744kb | C++11 | 2.4kb | 2023-03-22 17:33:22 | 2023-03-22 17:33:24 |
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 = long 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 1.0 * (_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] = calc_dist(i, j);
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);
// cerr << "merge " << u << " " << v << '\n';
cout << siz[u] << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3716kb
input:
2 0 0 1 0
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 4047ms
memory: 198652kb
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: 3933ms
memory: 198656kb
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: 4000ms
memory: 198744kb
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: 4049ms
memory: 198716kb
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: 6040ms
memory: 198628kb
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'