結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2019-07-17 17:03:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 82 ms / 2,000 ms |
コード長 | 2,359 bytes |
コンパイル時間 | 1,878 ms |
コンパイル使用メモリ | 175,852 KB |
実行使用メモリ | 15,844 KB |
最終ジャッジ日時 | 2024-12-22 20:50:12 |
合計ジャッジ時間 | 3,456 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:41, from main.cpp:1: In function 'constexpr typename __gnu_cxx::__enable_if<std::__is_integer<_Tp>::__value, double>::__type std::sqrt(_Tp) [with _Tp = long long int]', inlined from 'int main()' at main.cpp:114:16: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/cmath:476:28: warning: 'original' may be used uninitialized [-Wmaybe-uninitialized] 476 | { return __builtin_sqrt(__x); } | ~~~~~~~~~~~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:105:8: note: 'original' was declared here 105 | ll original; | ^~~~~~~~
ソースコード
#include "bits/stdc++.h"#define REP(i, n, N) for(ll i=(n); i<(N); i++)#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)#define CK(n, a, b) ((a)<=(n)&&(n)<(b))#define ALL(v) (v).begin(),(v).end()#define MCP(a, b) memcpy(b,a,sizeof(b))#define P(s) cout<<(s)<<endl#define P2(a, b) cout<<(a)<<" "<<(b)<<endl#define V2(T) vector<vector<T>>typedef long long ll;using namespace std;const ll MOD = 1e9 + 7;const ll INF = 1e18;struct point_dist{ll point1;ll point2;ll dist;};struct points{ll x;ll y;};bool cmp(const point_dist& A, const point_dist& B){return A.dist < B.dist;}ll pow(ll A){return A*A;}const int MAX_N = 100010;struct UnionFind {int par[MAX_N]; // 親ノードの番号int deph[MAX_N]; // ノードの深さUnionFind(int n) {fill(par, par + MAX_N, -1);for (int i = 0; i<n; i++) {par[i] = i;deph[i] = 0;}}int find(int x) {if (par[x] == x) {return x;} else {return par[x] = find(par[x]);}}void unite(int x, int y) {x = find(x);y = find(y);if (x == y) {/* 同じグループに属しているときの処理// istree = false;*/return;}if (deph[x] < deph[y]) {par[x] = par[y];} else {par[y] = par[x];if (deph[x] == deph[y]) deph[x]++;}}bool same(int x, int y) {return find(x) == find(y);}};int main(){ll n,x,y;cin >> n;vector<points> ps(n+1);vector<point_dist> pd;REP(i,1,n+1){cin >> x >> y;ps[i].x=x;ps[i].y=y;}REP(i,1,n+1){REP(j,i+1,n+1){pd.push_back({i,j,pow(abs(ps[i].x-ps[j].x))+pow(abs(ps[i].y-ps[j].y))});}}/**for(auto item:pd){P2(item.point1,item.point2);}**/sort(pd.begin(),pd.end(),cmp);UnionFind uf(n);ll original;for(auto item : pd){uf.unite(item.point1,item.point2);if(uf.same(1,n)){original = item.dist;break;}}ll d = sqrt(original);while(original > d * d) d++;d = (d + 9LL) / 10LL * 10LL;cout << d << endl;/**if(original%100==0){P(((ll)sqrt(original)/10)*10);}else{P(((ll)sqrt(original)/10)*10+10);}**/}