結果

問題 No.96 圏外です。
ユーザー mkawa2mkawa2
提出日時 2020-01-16 13:57:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 3,385 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 11,268 KB
実行使用メモリ 82,152 KB
最終ジャッジ日時 2023-09-05 21:40:38
合計ジャッジ時間 16,118 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
9,040 KB
testcase_01 AC 19 ms
8,816 KB
testcase_02 AC 19 ms
9,052 KB
testcase_03 AC 20 ms
8,996 KB
testcase_04 AC 33 ms
10,488 KB
testcase_05 AC 43 ms
11,704 KB
testcase_06 AC 56 ms
13,096 KB
testcase_07 AC 83 ms
14,740 KB
testcase_08 AC 106 ms
18,520 KB
testcase_09 AC 149 ms
21,088 KB
testcase_10 AC 231 ms
24,204 KB
testcase_11 AC 281 ms
30,668 KB
testcase_12 AC 348 ms
35,104 KB
testcase_13 AC 540 ms
38,472 KB
testcase_14 AC 603 ms
48,624 KB
testcase_15 AC 896 ms
48,132 KB
testcase_16 AC 971 ms
64,360 KB
testcase_17 AC 1,105 ms
82,152 KB
testcase_18 AC 1,235 ms
73,916 KB
testcase_19 AC 1,227 ms
74,036 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
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 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
        # 凸包を作る
        v.sort(key=lambda p: (p[0], p[1]))
        # 下部分
        x0, y0 = v[0]
        under = []
        for x, y in v[1:]:
            vx, vy = x - x0, y - y0
            while under:
                x1, y1 = under[-1]
                vx1, vy1 = x1 - x0, y1 - y0
                if vx1 * vy - vy1 * vx > 0: break
                under.pop()
            under.append((x, y))
        # 上部分
        x0, y0 = v[-1]
        upper = []
        for x, y in v[-1::-1]:
            vx, vy = x0 - x, y0 - y
            while upper:
                x1, y1 = upper[-1]
                vx1, vy1 = x0 - x1, y0 - y1
                if vx1 * vy - vy1 * vx > 0: break
                upper.pop()
            upper.append((x, y))
        cnv = under + upper
        # print(v, 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