QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#89388 | #5251. Constellations | Milk_Feng | WA | 358ms | 136636kb | C++ | 2.2kb | 2023-03-19 22:04:34 | 2023-03-19 22:04:36 |
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];
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 = i + 1; j <= n; ++j) {
dis_[i][j] = dis_[j][i] = (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;
Pair mn = *s[*exist.begin()].begin();
for(int i: exist) {
if(s[i].empty()) continue;
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) 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 && i != id2) s[i].insert(Pair(i, n));
exist.erase(id1), exist.erase(id2);
exist.insert(n);
printf("%lld\n", sz[n]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3700kb
input:
2 0 0 1 0
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 358ms
memory: 136636kb
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: ''