結果

問題 No.96 圏外です。
ユーザー colognecologne
提出日時 2022-01-31 20:03:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,235 ms / 5,000 ms
コード長 2,939 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 135,140 KB
最終ジャッジ日時 2024-06-11 09:04:03
合計ジャッジ時間 16,962 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
60,672 KB
testcase_01 AC 56 ms
60,416 KB
testcase_02 AC 52 ms
60,928 KB
testcase_03 AC 43 ms
52,736 KB
testcase_04 AC 130 ms
79,616 KB
testcase_05 AC 148 ms
79,744 KB
testcase_06 AC 160 ms
79,872 KB
testcase_07 AC 196 ms
81,024 KB
testcase_08 AC 209 ms
82,048 KB
testcase_09 AC 245 ms
84,608 KB
testcase_10 AC 402 ms
86,656 KB
testcase_11 AC 354 ms
86,400 KB
testcase_12 AC 359 ms
88,704 KB
testcase_13 AC 731 ms
96,256 KB
testcase_14 AC 655 ms
101,340 KB
testcase_15 AC 1,066 ms
106,392 KB
testcase_16 AC 928 ms
110,452 KB
testcase_17 AC 904 ms
121,848 KB
testcase_18 AC 1,147 ms
122,232 KB
testcase_19 AC 1,156 ms
122,600 KB
testcase_20 AC 1,235 ms
121,088 KB
testcase_21 AC 852 ms
115,060 KB
testcase_22 AC 984 ms
135,140 KB
testcase_23 AC 1,073 ms
122,236 KB
testcase_24 AC 50 ms
60,672 KB
testcase_25 AC 610 ms
99,148 KB
testcase_26 AC 800 ms
107,388 KB
testcase_27 AC 684 ms
108,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect


def input(): return sys.stdin.readline().rstrip()


class DisjointSet:

    sys.setrecursionlimit(10**6)

    def __init__(self, N):
        self.par = list(range(N))

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

    def union(self, a, b):
        self.par[self.find(a)] = self.find(b)


def ccw(p1, p2, p3):
    x1, y1 = p1
    x2, y2 = p2
    x3, y3 = p3
    return (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)


def dist(xy):
    if len(xy) <= 1:
        return 0
    if len(xy) == 2:
        (x1, y1), (x2, y2) = xy
        return ((x2-x1)**2 + (y2-y1)**2)**0.5

    xy.sort()

    upper, lower = [], []
    for pt in xy:
        while len(upper) >= 2:
            if ccw(upper[-2], upper[-1], pt) >= 0:
                upper.pop()
            else:
                break
        upper.append(pt)

        while len(lower) >= 2:
            if ccw(lower[-2], lower[-1], pt) <= 0:
                lower.pop()
            else:
                break
        lower.append(pt)

    lower.extend(upper[-2:0:-1])
    if len(lower) == 2:
        (x1, y1), (x2, y2) = lower
        return ((x2-x1)**2 + (y2-y1)**2)**0.5

    ans = 0
    j = 2
    for i in range(len(lower)):
        ni = 0 if i + 1 == len(lower) else i + 1
        while True:
            nj = 0 if j + 1 == len(lower) else j + 1
            if ccw(lower[i], lower[ni], lower[j]) <= \
                    ccw(lower[i], lower[ni], lower[nj]):
                j = nj
            else:
                break
        x1, y1 = lower[i]
        x2, y2 = lower[ni]
        x3, y3 = lower[j]
        ans = max(ans, (x3-x1)**2+(y3-y1)**2, (x3-x2)**2+(y3-y2)**2)

    return ans ** 0.5


def main():
    N = int(input())

    if N == 0:
        print(1)
        return

    MAX = 10000

    xpos = [[] for i in range(MAX*2+1)]
    coord = {}
    xy = []
    for i in range(N):
        x, y = [int(v)+MAX for v in input().split()]
        xpos[x].append(y)
        coord[(x, y)] = i
        xy.append((x, y))

    ds = DisjointSet(N)

    for x in range(len(xpos)):
        xpos[x].sort()
        for j in range(len(xpos[x])-1):
            yp, yn = xpos[x][j], xpos[x][j+1]
            if yn-yp <= 10:
                ds.union(coord.get((x, yp)), coord.get((x, yn)))

    for (x, y), v in coord.items():
        for xt in range(max(0, x-10), x):
            yt = int(math.sqrt(100-(x-xt)**2))
            L = bisect.bisect_left(xpos[xt], y-yt)
            R = bisect.bisect_right(xpos[xt], y+yt)
            if L != R:
                ds.union(v, coord.get((xt, xpos[xt][L])))
                if L != R-1:
                    ds.union(v, coord.get((xt, xpos[xt][R-1])))

    connected = [[] for i in range(N)]
    for i in range(N):
        connected[ds.find(i)].append(xy[i])

    print(max(map(dist, connected)) + 2)


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