結果

問題 No.168 ものさし
ユーザー cormorancormoran
提出日時 2016-09-01 00:11:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,782 bytes
コンパイル時間 2,167 ms
コンパイル使用メモリ 171,676 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 21:02:27
合計ジャッジ時間 2,870 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 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 3 ms
4,376 KB
testcase_11 AC 12 ms
4,376 KB
testcase_12 AC 35 ms
4,376 KB
testcase_13 AC 47 ms
4,380 KB
testcase_14 AC 49 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 34 ms
4,376 KB
testcase_20 AC 34 ms
4,376 KB
testcase_21 AC 35 ms
4,380 KB
testcase_22 AC 34 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)

// pair
template<class T, class U> istream& operator >> (istream &is , pair<T, U> &v) { return is >> v.first >> v.second; }
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << " " << v.second << ">"; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

struct UnionFind{
  int n;
  vector<int> p;
  UnionFind(int nn):n(nn+1){
      p.resize(n);
      rep(i,n) p[i] = i;
  }
  int root(int x){
    if(p[x] == x) return x;
    else return p[x] = root(p[x]);
  }
  void unite(int x,int y){
      x = root(x);
      y = root(y);
      if(x != y) p[y] = x;
  }
  bool query(int x,int y){
    return root(x) == root(y);
  }
};


const int INF = 1 << 30;
const ll INFL = 1LL << 60;
class Solver {
  public:
    int N;
    vector<pii> P;

    ll distance2(pii &a, pii &b) {
        ll x = a.first - b.first, y = a.second - b.second;
        return (ll)x * x + (ll)y * y;
    }
    bool check(ll l) {
        l *= l;
        UnionFind uf(N);
        rep(i, N) {
            rep(j, i) {
                if(distance2(P[i], P[j]) <= l) uf.unite(i, j);
            }
        }
        return uf.query(0, N - 1);
    }
    bool solve() {
        cin >> N;
        P.resize(N);
        cin >> P;

        ll l = 0, r = 1e10;
        while(l + 1 < r) {
            ll m = (l + r) / 2;
            (check(m) ? r : l) = m;
        }
        while(r % 10) r++;
        cout << r << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0