結果
問題 | No.96 圏外です。 |
ユーザー |
|
提出日時 | 2017-01-07 00:15:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,573 bytes |
コンパイル時間 | 1,108 ms |
コンパイル使用メモリ | 93,752 KB |
実行使用メモリ | 31,360 KB |
最終ジャッジ日時 | 2024-12-24 09:12:36 |
合計ジャッジ時間 | 20,191 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 WA * 1 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <functional>#include <cmath>#include <cassert>#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)using namespace std;template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }bool is_on_field(int y, int x, int h, int w) { return 0 <= y and y < h and 0 <= x and x < w; }int main() {int n; cin >> n;vector<int> x(n), y(n);repeat (i,n) {cin >> x[i] >> y[i];x[i] += 10000;y[i] += 10000;assert (0 <= y[i] and y[i] <= 20000);assert (0 <= x[i] and x[i] <= 20000);}function<double (int, int)> dist = [&](int i, int j) { return hypot(x[i] - x[j], y[i] - y[j]); };function<int (int, vector<int> const &)> farthest = [&](int i, vector<int> const & acc) {return *whole(max_element, acc, [&](int j, int k) { return dist(i, j) < dist(i, k); });};const int Q = 20;const int K = 20000 / Q + 1;assert (20000 / Q < K);auto bucket = vectors(K, K, vector<int>());repeat (i,n) bucket[y[i] / Q][x[i] / Q].push_back(i);double ans = 1;vector<bool> used(n);repeat (i,n) if (not used[i]) {vector<int> acc; {int it = 0;acc.push_back(i);used[i] = true;while (it < acc.size()) {int j = acc[it]; ++ it;for (int dy : { -1, 0, 1 }) {for (int dx : { -1, 0, 1 }) {int ny = y[j] / Q + dy;int nx = x[j] / Q + dx;if (is_on_field(ny, nx, K, K)) {for (int k : bucket[ny][nx]) if (not used[k] and dist(j, k) <= 10) {acc.push_back(k);used[k] = true;}}}}}}whole(random_shuffle, acc);repeat (i, min<int>(300, acc.size())) {int j = farthest(i, acc);int k = farthest(j, acc);setmax(ans, dist(j, k) + 2);}}printf("%.9lf\n", ans);return 0;}