結果

問題 No.96 圏外です。
ユーザー mkawa2mkawa2
提出日時 2020-01-16 18:39:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 3,145 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 11,128 KB
実行使用メモリ 82,252 KB
最終ジャッジ日時 2023-09-06 05:28:00
合計ジャッジ時間 20,176 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
9,208 KB
testcase_01 AC 20 ms
8,948 KB
testcase_02 AC 20 ms
9,256 KB
testcase_03 AC 19 ms
8,888 KB
testcase_04 AC 33 ms
10,516 KB
testcase_05 AC 43 ms
11,684 KB
testcase_06 AC 58 ms
13,236 KB
testcase_07 AC 86 ms
14,836 KB
testcase_08 AC 114 ms
18,488 KB
testcase_09 AC 168 ms
21,056 KB
testcase_10 AC 247 ms
24,224 KB
testcase_11 AC 302 ms
30,812 KB
testcase_12 AC 363 ms
34,872 KB
testcase_13 AC 567 ms
38,560 KB
testcase_14 AC 698 ms
48,476 KB
testcase_15 AC 942 ms
48,148 KB
testcase_16 AC 1,066 ms
64,484 KB
testcase_17 AC 1,274 ms
82,252 KB
testcase_18 AC 1,397 ms
73,960 KB
testcase_19 AC 1,372 ms
74,028 KB
testcase_20 AC 1,909 ms
44,264 KB
testcase_21 AC 1,507 ms
69,188 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

class UnionFind:
    def __init__(self, n):
        self.state = [-1] * n

    def root(self, u):
        pu = self.state[u]
        if pu < 0: return u
        res = self.state[u] = self.root(pu)
        return res

    def merge(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        state = self.state
        if ru == rv: return
        if state[ru] > state[rv]: ru, rv = rv, ru
        if state[ru] == state[rv]: state[ru] -= 1
        state[rv] = ru

def ConvexHull(xy):
    def NG(x, y):
        x0, y0 = res[-2]
        x1, y1 = res[-1]
        return (x - x0) * (y1 - y0) - (x1 - x0) * (y - y0) >= 0

    #if len(xy) < 3: return xy
    res = []
    xy.sort(key=lambda p: (p[0], p[1]))
    for x, y in xy:
        while len(res) > 1 and NG(x, y): res.pop()
        res.append((x, y))
    under_n = len(res)
    for x, y in xy[-2::-1]:
        while len(res) > under_n and NG(x, y): res.pop()
        res.append((x, y))
    return res[:-1]

def main():
    n = II()

    # 例外処理
    if n == 0:
        print(1)
        exit()

    # 負の座標が面倒なので10000を足して正にする
    # 座標平面を一辺10の正方形ゾーンに分割して、座標をゾーンごとに振り分ける
    zone = {}
    xy = []
    for i in range(n):
        x, y = MI()
        x, y = x + 10000, y + 10000
        xy.append((x, y))
        x, y = x // 10, y // 10
        zone.setdefault((x, y), [])
        zone[x, y].append(i)
    # print(zone)

    # 自分自身も含めて隣接9ゾーンで10km以内の座標同士を結合していく
    # 実際は未訪の5ゾーン(自分と上と右3つ)を調べればよい
    uf = UnionFind(n)
    for (zx, zy), ii in sorted(zone.items(), key=lambda k: (k[0], k[1])):
        for i in ii:
            ix, iy = xy[i]
            for nzx, nzy in [(zx, zy), (zx, zy + 1), (zx + 1, zy - 1), (zx + 1, zy), (zx + 1, zy + 1)]:
                if (nzx, nzy) not in zone: continue
                for j in zone[nzx, nzy]:
                    if i == j: continue
                    jx, jy = xy[j]
                    if (ix - jx) ** 2 + (iy - jy) ** 2 <= 100: uf.merge(i, j)

    # 結合成分どうしでグループ分け
    rtoxy = defaultdict(list)
    for i in range(n):
        rtoxy[uf.root(i)].append(xy[i])
    # print(rtoxy)

    # グループごとに最遠点を計算
    ans = 0
    for v in rtoxy.values():
        if len(v) == 1: continue
        # 凸包を作る
        cnv=ConvexHull(v)
        #print(cnv)
        # 凸包の中で距離を全探索
        for i, (ix, iy) in enumerate(cnv):
            for jx, jy in cnv[:i]:
                d = (ix - jx) ** 2 + (iy - jy) ** 2
                if d > ans: ans = d
    print(ans ** 0.5 + 2)

main()
0