結果

問題 No.168 ものさし
ユーザー IL_mstaIL_msta
提出日時 2015-07-11 20:16:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 871 ms / 2,000 ms
コード長 2,457 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 10,844 KB
最終ジャッジ日時 2023-08-25 20:58:23
合計ジャッジ時間 7,055 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
7,340 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 86 ms
7,136 KB
testcase_12 AC 501 ms
9,808 KB
testcase_13 AC 838 ms
10,844 KB
testcase_14 AC 543 ms
10,612 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 12 ms
4,532 KB
testcase_19 AC 789 ms
10,460 KB
testcase_20 AC 799 ms
10,632 KB
testcase_21 AC 860 ms
10,552 KB
testcase_22 AC 871 ms
10,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <cmath>

#include <string>
#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>

/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;

#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
unsigned long long Len[1000][1000];

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(10);//

	/*unsigned long long asd;
	asd = 1000000000;
	P(asd*asd*2);
	return 0;
	*/
	int N;
	cin>>N;//[2,1000]
	unsigned long long X[1000],Y[1000];
	rep(i,N){
		cin>>X[i]>>Y[i];
	}
	unsigned long long Lmin=0,tLmin;
	unsigned long long Amax=0;
	for(int i=0;i<N;++i){
		Lmin = 0xFFFFFFFFFFFFFFFF;
		for(int k=i+1;k<N;++k){
			if(i==k)continue;
			if(X[k] > X[i] ){
				Len[i][k] = (X[k]-X[i])*(X[k]-X[i]);
			}else{
				Len[i][k] = (X[i]-X[k])*(X[i]-X[k]);
			}
			if(Y[k] > Y[i] ){
				Len[i][k] += (Y[k]-Y[i])*(Y[k]-Y[i]);
			}else{
				Len[i][k] += (Y[i]-Y[k])*(Y[i]-Y[k]);
			}
		}
	}
	///////////
	int team[1001];
	rep(i,N){
		team[i] = i;
	}
	
	Lmin=0;
	//tLmin;
	Amax = 0;
	int minNo = -1;
	int minI,minK;
	while(team[N-1] != 0)
	{
		minNo = -1;
		Lmin = 0;
		minI = -1;
		minK = -1;
		for(int i=0;i<N;++i){
			for(int k=i+1;k<N;++k){
				if(i==k)continue;
				if(team[i] == team[k])continue;
				tLmin = Len[i][k];
				if(Lmin == 0 || Lmin > tLmin){
					Lmin = tLmin;
					minNo = k;
					minI = i;
					minK = k;
				}
			}
		}
		////
		if(team[minI] < team[minK]){
			minNo = team[minK];
			for(int no=0;no<N;++no){
				if(team[no] == minNo){
					team[no] = team[minI];
				}
			}
		}else{
			minNo = team[minI];
			for(int no=0;no<N;++no){
				if(team[no] == minNo ){
					team[no] = team[minK];
				}
			}
		}
		if(Lmin != 0){
			Amax = max(Amax,Lmin);
		}
	}
	
	///////////
	unsigned long long ans,Left,Right,Mid;
	Left = 0;
	Right = 1414213563;
	{
		do
		{
			Mid = (Right+Left)/2;
			if( Mid*Mid < Amax){
				Left = Mid;
			}else if( Amax < Mid*Mid ){
				Right = Mid; 
			}else{
				break;
			}
		}while( Mid*Mid > Amax || Amax > (Mid+1)*(Mid+1) );
		ans = Mid;
	}
	///////////////
	ans = (ans + 9)/10*10;
	while(Amax > ans*ans){
		ans += 10;
	}
	//ans *= 10;
	P( ans );
    return 0;
}
0