結果

問題 No.96 圏外です。
ユーザー kimiyukikimiyuki
提出日時 2017-02-06 17:42:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,837 ms / 5,000 ms
コード長 2,818 bytes
コンパイル時間 1,088 ms
コンパイル使用メモリ 91,592 KB
実行使用メモリ 30,940 KB
最終ジャッジ日時 2023-08-25 23:04:42
合計ジャッジ時間 18,796 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
26,524 KB
testcase_01 AC 21 ms
26,624 KB
testcase_02 AC 21 ms
26,656 KB
testcase_03 AC 22 ms
26,520 KB
testcase_04 AC 24 ms
27,132 KB
testcase_05 AC 27 ms
27,260 KB
testcase_06 AC 28 ms
27,232 KB
testcase_07 AC 30 ms
27,344 KB
testcase_08 AC 36 ms
27,608 KB
testcase_09 AC 40 ms
27,908 KB
testcase_10 AC 49 ms
27,760 KB
testcase_11 AC 56 ms
27,956 KB
testcase_12 AC 67 ms
28,360 KB
testcase_13 AC 92 ms
27,992 KB
testcase_14 AC 98 ms
28,712 KB
testcase_15 AC 275 ms
28,560 KB
testcase_16 AC 140 ms
29,680 KB
testcase_17 AC 153 ms
30,940 KB
testcase_18 AC 174 ms
29,924 KB
testcase_19 AC 172 ms
30,040 KB
testcase_20 AC 3,471 ms
29,092 KB
testcase_21 AC 3,837 ms
29,792 KB
testcase_22 AC 3,543 ms
28,696 KB
testcase_23 AC 3,402 ms
28,872 KB
testcase_24 AC 22 ms
26,496 KB
testcase_25 AC 111 ms
29,828 KB
testcase_26 AC 142 ms
30,416 KB
testcase_27 AC 121 ms
30,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
                            }
                        }
                    }
                }
            }
        }
        if (acc.size() < 300) {
            repeat (j, acc.size()) {
                repeat (i, j+1) {
                    setmax(ans, dist(acc[i], acc[j]) + 2);
                }
            }
        } else {
            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;
}
0