QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#89345 | #5251. Constellations | Milk_Feng | WA | 641ms | 230292kb | C++ | 3.5kb | 2023-03-19 20:28:38 | 2023-03-19 20:28:42 |
Judging History
answer
#include <bits/stdc++.h>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
//typedef __int128 LLL;
int read() {
int x = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') c == '-' ? f = -1: 0, c = getchar();
while(c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
return x * f;
}
LL X[5050], Y[5050], sz[5050], dis_[5050][5050];
struct Pair {
int i, j;
Pair(int _i, int _j): i(_i), j(_j) {}
bool operator < (const Pair &o) const {
int thisnew = max(i, j), thisold = min(i, j);
int othernew = max(o.i, o.j), otherold = min(o.i, o.j);
LL tmp1 = dis_[i][j] * sz[o.i] * sz[o.j];
LL tmp2 = dis_[o.i][o.j] * sz[i] * sz[j];
// cout << tmp1 << ' ' << tmp2 << ' ' << thisold << ' ' << otherold << ' ' << thisnew << ' ' << othernew << endl;
if(tmp1 == tmp2) {
if(thisold == otherold) return thisnew < othernew;
else return thisold < otherold;
}
else return tmp1 < tmp2;
}
};
set<Pair> s[4050];
set<int> exist;
signed main() {
int n = read();
for(int i = 1; i <= n; ++i) X[i] = read(), Y[i] = read();
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
if(i == j) continue;
dis_[i][j] = (X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]);
s[i].insert(Pair(i, j));
}
exist.insert(i);
sz[i] = 1;
}
while(exist.size() > 1) {
if(n > 100) break;
// cout << "exist: ";
// for(int i: exist) cout << i << ' ';
// cout << endl;
// for(int i: exist) {
// for(Pair pair: s[i]) {
// int j = pair.j;
// cout << 1.0 * dis_[i][j] / sz[i] / sz[j] << ' ';
// }
// cout << endl;
// }
// cout << endl;
//
// cout << "dis: " << endl;
// for(int i: exist) {
// for(int j: exist) {
// if(i == j) cout << "0 ";
// else cout << 1.0 * dis_[i][j] / sz[i] / sz[j] << ' ';
// }
// cout << endl;
// }
Pair mn = *s[*exist.begin()].begin();
for(int i: exist) {
Pair pair = *(s[i].begin());
if(pair < mn) mn = pair;
}
int id1 = mn.i, id2 = mn.j;
sz[++n] = sz[id1] + sz[id2];
for(int i: exist) {
if(i == id1 || i == id2) continue;
dis_[i][n] = dis_[n][i] = dis_[i][id1] + dis_[i][id2];
}
for(int i: exist) {
if(i != id1) {
// int sss = s[i].size();
s[i].erase(s[i].lower_bound(Pair(i, id1)));
// cout << "delta: " << sss - s[i].size() << ' ' << i << ' ' << id1 << endl;
}
if(i != id2) {
// int sss = s[i].size();
s[i].erase(s[i].lower_bound(Pair(i, id2)));
// cout << "delta: " << sss - s[i].size() << ' ' << i << ' ' << id2 << endl;
}
if(i != id1 && i != id2) s[i].insert(Pair(i, n)), s[n].insert(Pair(n, i));
}
// cout << id1 << ' ' << id2 << " -> " << n << endl;
exist.erase(id1), exist.erase(id2);
exist.insert(n);
printf("%lld\n", sz[n]);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3636kb
input:
2 0 0 1 0
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 641ms
memory: 230292kb
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:
result:
wrong answer 1st lines differ - expected: '2', found: ''