結果

問題 No.96 圏外です。
ユーザー しらっ亭しらっ亭
提出日時 2015-08-31 00:06:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,383 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 11,324 KB
実行使用メモリ 275,720 KB
最終ジャッジ日時 2023-09-25 19:57:55
合計ジャッジ時間 31,859 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,932 KB
testcase_01 AC 20 ms
9,096 KB
testcase_02 AC 21 ms
8,964 KB
testcase_03 AC 20 ms
8,960 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 RE -
testcase_21 AC 1,999 ms
117,316 KB
testcase_22 AC 3,274 ms
55,376 KB
testcase_23 AC 3,342 ms
55,560 KB
testcase_24 AC 20 ms
8,956 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from itertools import combinations
import math


class UnionFind:
    def __init__(self, n):
        self.par = list(range(n))

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        self.par[x] = y


def convex_hull(P):
    def veccross(A, B, C):
        return (C[0] - A[0]) * (B[1] - A[1]) - (C[1] - A[1]) * (B[0] - A[0])

    n = len(P)
    if n <= 2:
        return list(range(n))

    ps = [None] * n
    for i in range(n):
        ps[i] = (P[i], i)
    ps.sort()

    k = 0
    res = [0] * (n * 2)

    for i in range(n):
        while k > 1 and veccross(P[res[k - 2]], P[res[k - 1]], ps[i][0]) <= 0:
            k -= 1
        res[k] = ps[i][1]
        k += 1

    t = k
    for i in range(n - 2, -1, -1):
        while k > t and veccross(P[res[k - 2]], P[res[k - 1]], ps[i][0]) <= 0:
            k -= 1
        res[k] = ps[i][1]
        k += 1

    return res[:k - 1]


def m_dist(g, xs, ys):
    os = convex_hull([(xs[i], ys[i]) for i in g])
    ma = 0
    for i, j in combinations(os, 2):
        ma = max(ma, (xs[i] - xs[j]) ** 2 + (ys[i] - ys[j]) ** 2)
    return ma


def solve():
    N = int(input())
    XS = [0] * N
    YS = [0] * N

    B = defaultdict(list)

    def b(x, y):
        if 0 <= x <= 2000 and 0 <= y <= 2000:
            return B[x, y]
        else:
            return []

    ds = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]

    uf = UnionFind(N)

    for i in range(N):
        x, y = map(int, input().split())
        x += 10000
        y += 10000
        XS[i] = x
        YS[i] = y

        x10 = x // 10
        y10 = y // 10

        for dx, dy in ds:
            for j in b(x10 + dx, y10 + dy):
                if (x - XS[j]) ** 2 + (y - YS[j]) ** 2 <= 100:
                    uf.union(i, j)
        B[x10, y10].append(i)

    gd = defaultdict(set)
    for i in range(N):
        gd[uf.find(i)].add(i)

    gs = list(gd.values())

    if len(gs) == 0:
        print(1)
    else:
        ma = 0
        for g in gd.values():
            ma = max(ma, m_dist(g, XS, YS))
        print(math.sqrt(ma) + 2)


if __name__ == '__main__':
    solve()
0