結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2020-05-24 01:26:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 1,633 bytes |
コンパイル時間 | 1,961 ms |
コンパイル使用メモリ | 177,488 KB |
実行使用メモリ | 13,216 KB |
最終ジャッジ日時 | 2024-10-09 14:50:27 |
合計ジャッジ時間 | 3,473 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
/*** @FileName a.cpp* @Author kanpurin* @Created 2020.05.24 01:26:45**/#include "bits/stdc++.h"using namespace std;typedef long long ll;ll f(ll x1,ll x2, ll y1,ll y2) {ll res;for (res = ((ll)ceil(sqrt((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2)))) / 10 * 10; res * res < (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2); res+=10) {}return res;}// UnionFindclass UnionFind {private:vector<int> par;public:UnionFind(int n) {par.resize(n, -1);}int root(int x) {if (par[x] < 0) return x;return par[x] = root(par[x]);}bool unite(int x, int y) {int rx = root(x);int ry = root(y);if (rx == ry) return false;if (size(rx) < size(ry)) swap(rx, ry);par[rx] += par[ry];par[ry] = rx;return true;}bool same(int x, int y) {int rx = root(x);int ry = root(y);return rx == ry;}int size(int x) {return -par[root(x)];}};int main() {int n;cin >> n;vector<pair<int,int>> a(n);for (int i = 0; i < n; i++) {cin >> a[i].first >> a[i].second;}vector<tuple<ll,int,int>> v;for (int i = 0; i < n; i++) {for (int j = i + 1; j < n; j++) {v.push_back(make_tuple(f(a[i].first,a[j].first,a[i].second,a[j].second),i,j));}}sort(v.begin(), v.end());UnionFind uf(n);for (int i = 0; i < v.size(); i++) {uf.unite(get<1>(v[i]),get<2>(v[i]));if (uf.same(0,n-1)){cout << get<0>(v[i]) << endl;break;}}return 0;}