結果

問題 No.168 ものさし
ユーザー ei1333333ei1333333
提出日時 2015-07-26 20:07:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,554 bytes
コンパイル時間 1,293 ms
コンパイル使用メモリ 156,116 KB
実行使用メモリ 12,660 KB
最終ジャッジ日時 2023-08-25 20:58:27
合計ジャッジ時間 3,643 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
5,128 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 30 ms
5,284 KB
testcase_12 AC 97 ms
12,660 KB
testcase_13 AC 135 ms
12,428 KB
testcase_14 AC 136 ms
12,516 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 176 ms
12,108 KB
testcase_20 AC 185 ms
11,856 KB
testcase_21 AC 183 ms
12,016 KB
testcase_22 AC 183 ms
12,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
#define SQR(a) ((int64)(a)*(int64)(a))
struct edge {
  int u, v;
  int64 cost;
  bool operator<(const edge& e) const {
    return(cost < e.cost);
  }
};

class UnionFind{
private:
  vector< int > rank, p;
  void link(int x,int y){
    if(rank[x] > rank[y]){
      p[y] = x;
    }else{
      p[x] = y;
      if(rank[x] == rank[y]) rank[y]++;
    }
  }
public:
  UnionFind(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i = 0; i < rank.size(); i++){
      p[i] = i, rank[i] = 0;
    }
  }
  void Unite(int x,int y){
    link(Find(x),Find(y));
  }
  int Find(int x){
    return( x != p[x] ? p[x] = Find(p[x]) : p[x]);
  }
  bool Same(int a, int b) {
    return(Find(a) == Find(b));
  }
};

int main()
{
  int N, X[1000], Y[1000];
  cin >> N;
  UnionFind uf(N);
  for(int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
  }
  vector< edge > edges;
  for(int i = 0; i < N; i++) {
    for(int j = i + 1; j < N; j++) {
      int64 low = 0, high = 1LL << 32;
      while(high - low > 0) {
        int64 mid = (low + high) >> 1LL;
        if(SQR(mid) >= SQR(X[i] - X[j]) + SQR(Y[i] - Y[j])) high = mid;
        else low = mid + 1;
      }
      edges.push_back((edge){i, j, (low + 9) / 10LL * 10LL});
    }
  }
  sort(edges.begin(), edges.end());

  int64 ret = 0;

  for(int i = 0; i < edges.size(); i++) {
    edge& e = edges[i];
    if(uf.Same(e.u, e.v)) continue;
    ret = e.cost;
    uf.Unite(e.u, e.v);
    if(uf.Same(0, N - 1)) break;
  }
  cout << ret << endl;
}
0