結果

問題 No.168 ものさし
ユーザー not_522
提出日時 2015-08-19 02:02:25
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 2,053 bytes
コンパイル時間 1,828 ms
コンパイル使用メモリ 175,784 KB
実行使用メモリ 10,712 KB
最終ジャッジ日時 2024-07-18 10:27:46
合計ジャッジ時間 5,077 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 2 TLE * 1 -- * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

class UnionFind {
private:
  int n;
  vector<int> a;
public:
  UnionFind(int n) : n(n), a(n, -1) {}
  int find(int x) {return a[x] < 0 ? x : (a[x] = find(a[x]));}
  bool equal(int x, int y) {return find(x) == find(y);}
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] = x;
    --n;
  }
  int size() {return n;}
  int size(int x) {return -a[find(x)];}
};

template<typename T> inline T gcd(T a, T b) {
  return __gcd(a, b);
}

template<typename T> inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}

template<typename T> inline T floor(T a, T b) {
  return floor(a / b) * b <= a ? floor(a / b) : floor(a / b) - 1;
}

template<typename T> inline T ceil(T a, T b) {
  return floor(a + b - 1, b);
}

template<typename T> inline T round(T a, T b) {
  return floor(a + b / 2);
}

template<typename T> inline T mod(T a, T b) {
  return a - floor(a, b) * b;
}

template<typename T> inline T factorial(T n) {
  return n <= 1 ? 1 : factorial(n - 1) * n;
}

template<typename T> inline T square(T n) {
  return n * n;
}

template<typename T> inline T cube(T n) {
  return n * n * n;
}

template<typename T> inline T norm(T x1, T y1, T x2, T y2) {
  return square(x1 - x2) + square(y1 - y2);
}

inline long long sqrt(long long n) {
  long long a = std::sqrt(n);
  while (a != (n / a + a) / 2) a = (n / a + a) / 2;
  return a;
}

int main() {
  int n;
  cin >> n;
  vector<tuple<long long, long long>> p(n);
  for (auto& i : p) cin >> get<0>(i) >> get<1>(i);
  vector<tuple<long long, int, int>> dis;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      dis.emplace_back(make_tuple(norm(get<0>(p[i]), get<1>(p[i]), get<0>(p[j]), get<1>(p[j])), i, j));
    }
  }
  sort(dis.begin(), dis.end());
  UnionFind uf(n);
  for (const auto& d : dis) {
    uf.unite(get<1>(d), get<2>(d));
    if (uf.equal(0, n - 1)) {
      cout << ceil(sqrt(get<0>(d) - 1) + 1, 10ll) * 10 << endl;
      return 0;
    }
  }
}
0