結果

問題 No.96 圏外です。
ユーザー maine_honzuki
提出日時 2020-05-13 22:52:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 260 ms / 5,000 ms
コード長 3,375 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 189,968 KB
実行使用メモリ 115,248 KB
最終ジャッジ日時 2024-09-14 15:43:37
合計ジャッジ時間 8,074 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> convex_hull(vector<pair<int, int>> V) {
auto cross = [](pair<int, int> a, pair<int, int> b, pair<int, int> c) {
b.first -= a.first;
c.first -= a.first;
b.second -= a.second;
c.second -= a.second;
return (long long)b.first * c.second - (long long)b.second * c.first;
};
int n = (int)V.size();
sort(V.begin(), V.end(), [](pair<int, int> a, pair<int, int> b) {
return a.first != b.first ? a.first < b.first : a.second < b.second;
});
if (n == 1) return V;
int k = 0;
vector<pair<int, int>> ret(n * 2);
for (int i = 0; i < n; i++) {
while (k > 1 && cross(ret[k - 1], V[i], ret[k - 2]) >= 0)
k--;
ret[k++] = V[i];
}
for (int i = n - 2, t = k; i >= 0; i--) {
while (k > t && cross(ret[k - 1], V[i], ret[k - 2]) >= 0)
k--;
ret[k++] = V[i];
}
ret.resize(k - 1);
return ret;
}
struct UnionFind {
vector<int> data;
UnionFind(int n) {
data.assign(n, -1);
}
bool unite(int x, int y) {
x = root(x), y = root(y);
if (x == y)
return (false);
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return (true);
}
int root(int k) {
if (data[k] < 0)
return (k);
return (data[k] = root(data[k]));
}
bool same(int x, int y) {
return root(x) == root(y);
}
int size(int k) {
return (-data[root(k)]);
}
};
vector<int> B[2010][2010];
int main() {
int N;
vector<pair<int, int>> V;
cin >> N;
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
V.push_back({x + 10000, y + 10000});
}
if (N == 0) {
cout << 1 << endl;
return 0;
}
UnionFind uf(N);
auto check = [&](int a, int b) {
int xa = V[a].first, ya = V[a].second, xb = V[b].first, yb = V[b].second;
return abs(xa - xb) * abs(xa - xb) + abs(ya - yb) * abs(ya - yb) <= 100;
};
for (int i = 0; i < N; i++) {
int& x = V[i].first;
int& y = V[i].second;
int X = x / 10 + 1;
int Y = y / 10 + 1;
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
for (auto& n : B[X + dx][Y + dy]) {
if (check(i, n))
uf.unite(i, n);
}
}
}
B[X][Y].push_back(i);
}
map<int, vector<int>> V2;
for (int i = 0; i < N; i++) {
if (!V2.count(uf.root(i))) {
V2[uf.root(i)].reserve(uf.size(i));
}
V2[uf.root(i)].push_back(i);
}
auto dist = [](const pair<int, int>& a, const pair<int, int>& b) {
return sqrt(abs(a.first - b.first) * abs(a.first - b.first) + abs(a.second - b.second) * abs(a.second - b.second));
};
double ans = 0;
for (auto& p : V2) {
vector<pair<int, int>> V3;
V3.reserve(p.second.size());
for (auto& a : p.second)
V3.push_back({V[a].first, V[a].second});
V3 = convex_hull(V3);
for (auto& a : V3)
for (auto& b : V3)
ans = max(ans, dist(a, b) + 2);
}
cout << fixed << setprecision(9) << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0