QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#89318#5251. ConstellationsMilk_FengWA 3220ms359656kbC++142.2kb2023-03-19 19:22:342023-03-19 19:22:37

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-19 19:22:37]
  • 评测
  • 测评结果:WA
  • 用时:3220ms
  • 内存:359656kb
  • [2023-03-19 19:22:34]
  • 提交

answer

#include <bits/stdc++.h>
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[2050], Y[2050];
double dis[4050][4050];
LL dis_[4050][4050];
int size[4050];

struct Pair {
    int i, j;
    Pair(int _i, int _j) {i = _i, j = _j;}
    bool operator < (const Pair &o) const {
        
        int thisnew = min(i, j), thisold = max(i, j);
        int othernew = min(o.i, o.j), otherold = max(o.i, o.j);
        
        if(dis[i][j] == dis[o.i][o.j])
            return thisold == otherold ? thisnew > othernew : thisold > otherold;
        else return dis[i][j] < dis[o.i][o.j];
    }
};

set<Pair> s[4050];
set<int> exist;

signed main() {
    int n = read();
    for(int i = 1; i <= n; ++i) X[n - i + 1] = read(), Y[n - i + 1] = read();
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            if(i == j) continue;
            dis[i][j] = 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);
        size[i] = 1;
    }
    
    while(exist.size() > 1) {
        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;
        
        size[++n] = size[id1] + size[id2];        
        for(int i: exist) {
            if(i == id1 || i == id2) continue;
            dis_[i][n] = dis_[n][i] = dis_[i][id1] + dis_[i][id2];
            dis[i][n] = dis[n][i] = 1.0 * dis_[i][n] / size[i] / size[n];
        }
        
        for(int i: exist) {
            if(i != id1) s[i].erase(Pair(i, id1));
            if(i != id2) s[i].erase(Pair(i, id2));
            if(i != id1 && i != id2) s[i].insert(Pair(i, n)), s[n].insert(Pair(n, i));
        }
        
        exist.erase(id1), exist.erase(id2);
        exist.insert(n);
        
        printf("%d\n", size[n]);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3756kb

input:

2
0 0
1 0

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 3220ms
memory: 359656kb

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:

wrong answer 1969th lines differ - expected: '80', found: '96'