結果

問題 No.96 圏外です。
ユーザー nebukuro09nebukuro09
提出日時 2018-04-12 16:56:28
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,316 ms / 5,000 ms
コード長 3,183 bytes
コンパイル時間 2,294 ms
コンパイル使用メモリ 183,168 KB
実行使用メモリ 38,628 KB
最終ジャッジ日時 2023-09-03 19:25:42
合計ジャッジ時間 14,007 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 11 ms
6,204 KB
testcase_05 AC 17 ms
4,376 KB
testcase_06 AC 29 ms
4,412 KB
testcase_07 AC 46 ms
4,388 KB
testcase_08 AC 67 ms
8,076 KB
testcase_09 AC 92 ms
9,592 KB
testcase_10 AC 130 ms
9,596 KB
testcase_11 AC 168 ms
12,980 KB
testcase_12 AC 218 ms
14,256 KB
testcase_13 AC 293 ms
14,964 KB
testcase_14 AC 350 ms
13,996 KB
testcase_15 AC 466 ms
15,144 KB
testcase_16 AC 525 ms
14,788 KB
testcase_17 AC 637 ms
25,820 KB
testcase_18 AC 666 ms
25,612 KB
testcase_19 AC 683 ms
25,492 KB
testcase_20 AC 770 ms
38,628 KB
testcase_21 AC 316 ms
18,324 KB
testcase_22 AC 1,137 ms
19,880 KB
testcase_23 AC 1,316 ms
17,568 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 447 ms
14,280 KB
testcase_26 AC 576 ms
25,076 KB
testcase_27 AC 490 ms
21,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto P = N.iota.map!(_ => readln.split.map!(to!int)).map!(a => Point(a[0], a[1])).array;

    if (N == 0) {
        writeln(1);
        return;
    }

    Tuple!(int, int)[][int] X;
    foreach (i, p; P.enumerate) {
        X[p.x] ~= tuple(p.y, i.to!int);
    }
    foreach (k; X.keys) X[k].sort();

    auto uf = new UnionFind(N);
    foreach (i, p; P.enumerate) {
        foreach (dx; -10..11) {
            int nx = p.x + dx;
            if (nx !in X) continue;
            int j = X[nx].assumeSorted.lowerBound(tuple(p.y, 0)).length.to!int;
            for (int k = j; k < X[nx].length; ++k) {
                int ny = X[nx][k][0];
                if (dx * dx + (ny - p.y) * (ny - p.y) > 100) break;
                if (nx != p.x || ny != p.y) uf.unite(i.to!int, X[nx][k][1]);
            }
            for (int k = min(j, X[nx].length.to!int-1); k >= 0; --k) {
                int ny = X[nx][k][0];
                if (dx * dx + (ny - p.y) * (ny - p.y) > 100) break;
                if (nx != p.x || ny != p.y) uf.unite(i.to!int, X[nx][k][1]);            
            }
        }
    }

    int farest = 0;
    foreach (i; 0..N) {
        if (uf.groups[i].empty) continue;
        auto ch = convex_hull(uf.groups[i].map!(i => P[i]).array);
        foreach (j; 0..ch.length) {
            foreach (k; j+1..ch.length) {
                farest = max(farest, dist2(ch[j], ch[k]));
            }
        }
    }

    writefln("%.9f", sqrt(farest * 1.0L) + 2);
}

struct Point {
    int x;
    int y;
}

Point[] convex_hull(Point[] points) {
    int N = points.length.to!int;
    points.sort!((a, b) => a.x == b.x ? a.y < b.y : a.x < b.x);
    Point[] ch1, ch2;
    foreach (i; 0..N) {
        while (ch1.length >= 2 && rot(ch1[$-2], ch1[$-1], points[i]) <= 0) ch1.popBack;
        ch1 ~= points[i];
    }
    foreach_reverse (i; 0..N) {
        while (ch2.length >= 2 && rot(ch2[$-2], ch2[$-1], points[i]) <= 0) ch2.popBack;
        ch2 ~= points[i];
    }

    auto ch = ch1 ~ ch2;
    return ch.sort!((a, b) => a.x == b.x ? a.y < b.y : a.x < b.x).uniq.array;
}

int rot(Point a, Point b, Point c) {
    // a -> b -> c の向き
    // 正なら左、負なら右、0なら同一直線状
    return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}

int dist2(Point a, Point b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

class UnionFind {
    int N;
    int[] table;
    int[][] groups;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        groups = new int[][](N);
        foreach (i; 0..N) groups[i] = [i];
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
        groups[x] ~= groups[y];
        groups[y] = [];
    }
}

0