結果

問題 No.168 ものさし
ユーザー furafura
提出日時 2020-06-09 02:37:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 211,632 KB
実行使用メモリ 13,280 KB
最終ジャッジ日時 2023-08-28 13:00:08
合計ジャッジ時間 3,521 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
5,400 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 13 ms
5,136 KB
testcase_12 AC 41 ms
12,624 KB
testcase_13 AC 57 ms
12,476 KB
testcase_14 AC 58 ms
13,280 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 55 ms
12,280 KB
testcase_20 AC 57 ms
12,084 KB
testcase_21 AC 58 ms
11,896 KB
testcase_22 AC 58 ms
11,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

class union_find{
	int n;
	vector<int> p;
public:
	union_find(int n):n(n),p(n,-1){}
	int find(int u){ return p[u]<0?u:p[u]=find(p[u]); }
	void unite(int u,int v){
		u=find(u); v=find(v);
		if(u!=v){
			if(p[v]<p[u]) swap(u,v);
			p[u]+=p[v]; p[v]=u; n--;
		}
	}
	bool is_same(int u,int v){ return find(u)==find(v); }
	int size()const{ return n; }
	int size(int u){ return -p[find(u)]; }
};

int main(){
	int n; scanf("%d",&n);
	vector<lint> x(n),y(n);
	rep(i,n) scanf("%lld%lld",&x[i],&y[i]);

	vector<tuple<lint,int,int>> E;
	rep(i,n) rep(j,i) {
		E.emplace_back((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]),i,j);
	}
	sort(E.begin(),E.end());

	union_find U(n);
	for(const auto& e:E){
		U.unite(get<1>(e),get<2>(e));
		if(U.is_same(0,n-1)){
			lint ans=lint(sqrt(get<0>(e))-0.1)/10*10;
			while(ans*ans<get<0>(e)) ans+=10;
			printf("%lld\n",ans);
			break;
		}
	}
	return 0;
}
0