結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2016-09-01 00:11:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 1,782 bytes |
コンパイル時間 | 1,856 ms |
コンパイル使用メモリ | 173,416 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 07:14:51 |
合計ジャッジ時間 | 3,023 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#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++)// pairtemplate<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 << ">"; }// vectortemplate<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;}