結果
| 問題 |
No.94 圏外です。(EASY)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-07 22:02:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 5,000 ms |
| コード長 | 1,230 bytes |
| コンパイル時間 | 779 ms |
| コンパイル使用メモリ | 69,340 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 07:21:57 |
| 合計ジャッジ時間 | 1,611 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp:34:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | for(int i=0;i<N;i++)scanf("%d%d",&v[i].first,&v[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
class union_find{
int *parent,n;
public:
int root(int a){return parent[a]==a?a:(parent[a]=root(parent[a]));}
union_find(int _n){
n=_n;
parent=new int[n];
for(int i=0;i<n;i++)parent[i]=i;
}
~union_find(){delete []parent;}
int unite(int a,int b){
int x=root(a),y=root(b);if(x==y)return 0;
parent[y]=x;
return 1;
}
};
#define Z(a,b) ((a).first-(b).first)*((a).first-(b).first) + ((a).second-(b).second)*((a).second-(b).second)
int main(){
int N;
scanf("%d",&N);
if(N==0){
puts("1");
return 0;
}
vector<pair<int,int> >v(N);
for(int i=0;i<N;i++)scanf("%d%d",&v[i].first,&v[i].second);
sort(v.begin(),v.end());
union_find uf(N);
for(int i=0;i<N-1;i++){
int upper=upper_bound(v.begin(),v.end(),make_pair(v[i].first+10,9999999))-v.begin();
for(int j=i+1;j<upper;j++){
if(Z(v[i],v[j])<=100)uf.unite(i,j);
}
}
int result=0;
map<int,vector<int> >z;
for(int i=0;i<N;i++){
int r=uf.root(i);
z[r].push_back(i);
for(int j=0;j<z[r].size()-1;j++){
result=max(result,Z(v[z[r][j]],v[i]));
}
}
printf("%.9f\n",sqrt(result)+2);
}