結果

問題 No.168 ものさし
ユーザー not_522not_522
提出日時 2015-08-19 02:32:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,990 bytes
コンパイル時間 1,412 ms
コンパイル使用メモリ 161,588 KB
実行使用メモリ 20,936 KB
最終ジャッジ日時 2023-08-25 20:58:57
合計ジャッジ時間 3,328 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
8,948 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 27 ms
8,556 KB
testcase_12 AC 91 ms
19,540 KB
testcase_13 AC 128 ms
20,008 KB
testcase_14 AC 127 ms
19,988 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 124 ms
19,684 KB
testcase_20 AC 130 ms
20,936 KB
testcase_21 AC 130 ms
20,680 KB
testcase_22 AC 128 ms
20,920 KB
権限があれば一括ダウンロードができます

ソースコード

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) {
  return sqrt((long double)n);
}

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