結果
| 問題 |
No.94 圏外です。(EASY)
|
| コンテスト | |
| ユーザー |
tokkaka
|
| 提出日時 | 2016-07-30 16:40:06 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 5,000 ms |
| コード長 | 2,312 bytes |
| コンパイル時間 | 1,197 ms |
| コンパイル使用メモリ | 109,512 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 08:01:05 |
| 合計ジャッジ時間 | 2,128 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <tuple>
#include <climits>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <cmath>
#include <cstdlib>
#include <iomanip>
using namespace std;
class UnionFind
{
using data_type = size_t;
const data_type none = -1;
vector<data_type> data_;
set<data_type> roots_;
vector<data_type> size_;
data_type root(data_type index)
{
if(data_[index] == none)
return index;
data_[index] = root(data_[index]);
return data_[index];
}
public:
UnionFind(data_type size)
: data_(size, none), size_(size, 1)
{
}
void unite(data_type a, data_type b)
{
a = root(a);
b = root(b);
if(a == b) return;
if(size_[a] < size_[b]) {
data_[b] = a;
size_[b] = size_[a] + size_[b];
roots_.erase(a);
roots_.insert(b);
} else {
data_[a] = b;
size_[a] = size_[a] + size_[b];
roots_.erase(b);
roots_.insert(a);
}
}
bool isUnion(data_type a, data_type b)
{
return root(a) == root(b);
}
const set<data_type>& roots()
{
return roots_;
}
};
int main()
{
constexpr int repeater_range = 10;
constexpr int tranceiver_range = 1;
int N;
cin >> N;
if(N == 0) {
cout << 1 << endl;
return 0;
}
vector<int> X(N), Y(N);
UnionFind uf(N);
for(int i=0; i<N; i++)
cin >> X[i] >> Y[i];
for(int i=0; i<N; i++) {
for(int j=i+1; j<N; j++) {
const int distance_squared = (X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]);
if(distance_squared <= repeater_range*repeater_range)
uf.unite(i, j);
}
}
size_t max_length = 0;
for(const auto &x : uf.roots()) {
for(int i=0; i<N; i++) {
if(!uf.isUnion(x, i)) continue;
const int distance_squared = (X[x]-X[i])*(X[x]-X[i]) + (Y[x]-Y[i])*(Y[x]-Y[i]);
if(distance_squared > max_length) max_length = distance_squared;
}
}
cout << setprecision(11) << sqrt(max_length) + 2 << endl;
}
tokkaka