QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89366 | #5251. Constellations | Milk_Feng | WA | 563ms | 230460kb | C++ | 5.4kb | 2023-03-19 21:26:08 | 2023-03-19 21:26:11 |
Judging History
answer
#include <bits/stdc++.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
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) dis_[i][j] = (X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j)
if(i != 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;
// for(int i: exist) {
// for(Pair pair: s[i]) {
// int j = pair.j;
// cout << pair.i << ' ';
// }
// cout << endl;
// }
// cout << endl;
// for(int i: exist) {
// for(Pair pair: s[i]) {
// int j = pair.j;
// cout << pair.j << ' ';
// }
// cout << endl;
// }
// cout << endl;
//
// cout << "dis: " << endl;
// for(int i = 1; i <= n; ++i) cout << sz[i] << ' ';
// cout << endl;
// for(int i = 1; i <= n; ++i) {
// for(int j = 1; j <= n; ++j) {
// if(i == j) cout << "0 ";
// else cout << dis_[i][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) dis_[i][n] = dis_[n][i] = dis_[i][id1] + dis_[i][id2];
for(int i: exist) if(i != id1 && i != id2) s[i].insert(Pair(i, n)), s[n].insert(Pair(n, i));
for(int i: exist) if(i != id1) s[i].erase(Pair(i, id1));
for(int i: exist) if(i != id2) s[i].erase(Pair(i, id2));
// for(int i: exist) {
// if(i != id1) {
// int sss = s[i].size();
// cout << "delete: " << i << ' ' << id1 << endl;
// cout << (s[i].find(Pair(i, id1)) == s[i].end()) << endl;
//
// cout << "before: " << endl;
// for(Pair pair: s[i]) {
// cout << pair.i << ' ' << pair.j << ' ' << dis_[pair.i][pair.j] << endl;
// }
// s[i].erase(s[i].find(Pair(i, id1)));
// cout << "after: " << endl;
// for(Pair pair: s[i]) {
// cout << pair.i << ' ' << pair.j << ' ' << dis_[pair.i][pair.j] << endl;
// }
//
// cout << "delta: " << sss - s[i].size() << ' ' << i << ' ' << id2 << ' ' << dis_[i][id2] << endl;
// }
// if(i != id2) {
// int sss = s[i].size();
// cout << "delete: " << i << ' ' << id2 << endl;
// cout << "before: " << endl;
// for(Pair pair: s[i]) {
// cout << pair.i << ' ' << pair.j << ' ' << dis_[pair.i][pair.j] << endl;
// }
// s[i].erase(s[i].find(Pair(i, id2)));
//
// cout << "after: " << endl;
// for(Pair pair: s[i]) {
// cout << pair.i << ' ' << pair.j << ' ' << dis_[pair.i][pair.j] << endl;
// }
//
// cout << "delta: " << sss - s[i].size() << ' ' << i << ' ' << id2 << ' ' << dis_[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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3744kb
input:
2 0 0 1 0
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 563ms
memory: 230460kb
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: ''