結果
問題 | No.96 圏外です。 |
ユーザー |
|
提出日時 | 2016-02-18 07:38:15 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 171 ms / 5,000 ms |
コード長 | 3,108 bytes |
コンパイル時間 | 1,897 ms |
コンパイル使用メモリ | 174,960 KB |
実行使用メモリ | 112,032 KB |
最終ジャッジ日時 | 2024-12-24 08:31:24 |
合計ジャッジ時間 | 5,426 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:97:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 97 | scanf("%lld %lld", &x[i], &y[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;#define rep(i, a) for (int i = 0; i < (a); i++)#define rep2(i, a, b) for (int i = (a); i < (b); i++)#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }typedef long long ll;typedef double D;typedef complex<D> P;const D eps = 1e-8;D dot(P a, P b) { return real(conj(a) * b); }D cross(P a, P b) { return imag(conj(a) * b); }vector<P> convexfull(vector<P> &ps) {auto comp = [](P a, P b) {if (a.real() != b.real()) return a.real() < b.real();return a.imag() < b.imag();};int n = ps.size();sort(ps.begin(), ps.end(), comp);int k = 0;vector<P> qs(n * 2);for (int i = 0; i < n; i++) {while (k > 1 && cross(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0) k--;qs[k++] = ps[i];}for (int i = n - 2, t = k; i >= 0; i--) {while (k > t && cross(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0) k--;qs[k++] = ps[i];}qs.resize(k - 1);return qs;}double farthest(vector<P> &ps) {auto qs = convexfull(ps);int n = qs.size();if (n == 2) return abs(qs[0] - qs[1]);auto comp = [](P a, P b) {if (a.real() != b.real()) return a.real() < b.real();return a.imag() < b.imag();};int i = 0, j = 0;for (int k = 0; k < n; k++) {if (!comp(qs[i], qs[k])) i = k;if (comp(qs[j], qs[k])) j = k;}double ret = 0;int si = i, sj = j;while (i != sj || j != si) {ret = max(ret, abs(qs[i] - qs[j]));if (cross(qs[(i + 1) % n] - qs[i], qs[(j + 1) % n] - qs[j]) < 0) {i = (i + 1) % n;} else {j = (j + 1) % n;}}return ret;}struct UnionFind {vector<int> parent, size;UnionFind(int n) : parent(n), size(n, 1) { for (int i = 0; i < n; i++) parent[i] = i; }int operator[](int x) { return parent[x] == x ? x : (parent[x] = operator[](parent[x])); }bool merge(int x, int y) {if ((x = operator[](x)) == (y = operator[](y))) return false;parent[x] = parent[y] = size[x] > size[y] ? parent[x] : parent[y];size[x] = size[y] = size[x] + size[y];return true;}};ll hypot2(ll x, ll y) {return x * x + y * y;}int main() {int n;cin >> n;UnionFind uf(n);if (n == 0) {cout << 1 << endl;return 0;} else if (n == 1) {cout << 2 << endl;return 0;}vector<ll> x(n);vector<ll> y(n);static vector<int> bucket[2020][2020];rep(i, n) {scanf("%lld %lld", &x[i], &y[i]);x[i] += 10010;y[i] += 10010;bucket[x[i] / 10][y[i] / 10].push_back(i);}rep(i, n) {for (int dy = -1; dy <= 1; dy++) {for (int dx = -1; dx <= 1; dx++) {int bx = x[i] / 10;int by = y[i] / 10;for (int j : bucket[bx + dx][by + dy]) {if (hypot2(x[j] - x[i], y[j] - y[i]) <= 100) uf.merge(i, j);}}}}vector<vector<P>> ps(n);rep(i, n) ps[uf[i]].emplace_back(x[i], y[i]);double ans = 0;rep(i, n) if (!ps[i].empty()) chmax(ans, farthest(ps[i]));ans += 2;printf("%.20f\n", ans);return 0;}