QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#97599#5251. ConstellationsksunhokimWA 679ms143748kbC++201.5kb2023-04-17 12:12:472023-04-17 12:12:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-17 12:12:50]
  • 评测
  • 测评结果:WA
  • 用时:679ms
  • 内存:143748kb
  • [2023-04-17 12:12:47]
  • 提交

answer

#include <bits/stdc++.h>
#include <queue>
using namespace std;
using ll = long long;

// Union Find using disjoint subset union
struct union_find {
  int n;
  vector<int> p;
  vector<int> sz;
  union_find(int n) : n(n), p(n), sz(n, 1) {
    iota(begin(p),end(p), 0);
  }
  int leader(int x) {
    if (p[x] == x)
      return x;
    return p[x] = leader(p[x]);
  }
  void unite(int x, int y) {
    int l = leader(x), s = leader(y);
    if (l == s) return;
    if (sz[s] > sz[l]) swap(s,l);
    p[s] = l, sz[l] += sz[s];
  }
};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  int n;
  cin >> n;
  vector<pair<int,int>> A(n);
  for (int i=0;i<n;i++){
    cin >> A[i].first >> A[i].second;
  }

  auto get_dist = [&](pair<int,int> a, pair<int, int> b) {
    ll dx = (ll)a.first-b.first;
    ll dy = (ll)a.second-b.second;
    return dx*dx + dy*dy;
  };
  
  set<tuple<ll,int,int>> pq;
  for (int i=0;i<n;i++){
    for (int j=i+1;j<n;j++){
      pq.insert({get_dist(A[i],A[j]),i,j});
    }
  }

  vector<vector<int>> edges(n, vector<int>(n));
  union_find uf(n);

  for (auto [d,i,j] : pq) {
    int u = uf.leader(i), v = uf.leader(j);
    if (u == v) continue;
    edges[u][v]++;
    edges[v][u]++;
    if (edges[u][v] == uf.sz[u]*uf.sz[v]) {
      uf.unite(u,v);
      int nw = uf.leader(u);
      int old = u == nw ? v : u;
      for (int i=0;i<n;i++){
        edges[i][nw] += edges[i][old];
      }
      cout << uf.sz[nw] << "\n";
    }
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3464kb

input:

2
0 0
1 0

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 679ms
memory: 143748kb

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