QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#189351#5251. ConstellationstselmegkhWA 839ms115884kbC++202.1kb2023-09-27 13:16:512023-09-27 13:16:53

Judging History

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

  • [2023-09-27 13:16:53]
  • 评测
  • 测评结果:WA
  • 用时:839ms
  • 内存:115884kb
  • [2023-09-27 13:16:51]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>

using namespace std;

const int N = 4000 + 5, inf = 1e9;
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define sz(x) (int)x.size()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

struct Dat {
    int dis;
    int d;
    int mn, mx;
    Dat(int dis, int d, int mn, int mx){
        this->dis = dis;
        this->d = d;
        this->mn = mn;
        this->mx = mx;
    }
    bool operator<(const Dat &b) const{
        return (dis * b.d != b.dis * d) ? (dis * b.d < b.dis * d) : (mn != b.mn) ? mn < b.mn : mx < b.mx;
    }
    bool operator>(const Dat &b) const{
        return (b < *this);
    }
};

int a[N][N];
int sz[N];

void solve(){
    int n;
    cin >> n;
    vi x(n), y(n);

    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    priority_queue<Dat, vector<Dat>, greater<Dat>> pq;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int d = abs(x[i] - x[j]) * abs(x[i] - x[j]) + abs(y[i] - y[j]) * abs(y[i] - y[j]);
            a[i][j] = a[j][i] = d;
            pq.push(Dat(d, 1, i, j));
        }
    }
    for(int i = 0; i < n; i++){
        sz[i] = 1;
    }
    int cur = n;
    while(!pq.empty()){
        auto x = pq.top(); pq.pop();
        if(sz[x.mn] == 0 || sz[x.mx] == 0)continue;
        sz[cur] += sz[x.mn] + sz[x.mx];
        sz[x.mn] = sz[x.mx] = 0;
        cout << sz[cur] << '\n';
        for(int i = 0; i < 2 * n + 5; i++){
            if(cur == i || sz[i] == 0)continue;
            a[cur][i] = a[i][cur] = a[x.mn][i] + a[x.mx][i];
            pq.push(Dat(a[cur][i], sz[cur] * sz[i], min(cur, i), max(cur, i)));
        }
        cur++;
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3544kb

input:

2
0 0
1 0

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 839ms
memory: 115884kb

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 1785th lines differ - expected: '16', found: '24'