結果

問題 No.96 圏外です。
ユーザー mkawa2mkawa2
提出日時 2023-09-27 18:50:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,158 ms / 5,000 ms
コード長 3,748 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 13,184 KB
実行使用メモリ 75,948 KB
最終ジャッジ日時 2024-07-20 13:20:05
合計ジャッジ時間 23,536 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,136 KB
testcase_01 AC 31 ms
11,264 KB
testcase_02 AC 31 ms
11,136 KB
testcase_03 AC 32 ms
11,136 KB
testcase_04 AC 57 ms
12,160 KB
testcase_05 AC 73 ms
13,184 KB
testcase_06 AC 95 ms
14,592 KB
testcase_07 AC 138 ms
16,256 KB
testcase_08 AC 175 ms
18,760 KB
testcase_09 AC 236 ms
21,572 KB
testcase_10 AC 374 ms
25,272 KB
testcase_11 AC 418 ms
29,420 KB
testcase_12 AC 478 ms
36,224 KB
testcase_13 AC 938 ms
39,508 KB
testcase_14 AC 897 ms
47,132 KB
testcase_15 AC 1,591 ms
51,524 KB
testcase_16 AC 1,441 ms
64,652 KB
testcase_17 AC 1,447 ms
75,948 KB
testcase_18 AC 1,880 ms
75,172 KB
testcase_19 AC 1,903 ms
75,032 KB
testcase_20 AC 1,327 ms
58,996 KB
testcase_21 AC 2,158 ms
73,540 KB
testcase_22 AC 961 ms
51,220 KB
testcase_23 AC 1,001 ms
51,332 KB
testcase_24 AC 31 ms
11,136 KB
testcase_25 AC 976 ms
55,540 KB
testcase_26 AC 1,295 ms
70,700 KB
testcase_27 AC 1,043 ms
63,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 63)
md = 10**9+7
# md = 998244353

class UnionFind:
    def __init__(self, n):
        self.table = [-1]*n
        self.mem = [[u] for u in range(n)]
        self.cnt = n

    def root(self, u):
        stack = []
        while self.table[u] >= 0:
            stack.append(u)
            u = self.table[u]
        for v in stack: self.table[v] = u
        return u

    def same(self, u, v):
        return self.root(u) == self.root(v)

    def merge(self, u, v):
        u = self.root(u)
        v = self.root(v)
        if u == v: return False
        su = -self.table[u]
        sv = -self.table[v]
        if su < sv: u, v = v, u
        self.table[u] = -su-sv
        self.table[v] = u
        self.mem[u] += self.mem[v]
        self.mem[v].clear()
        self.cnt -= 1
        return True

    def member(self, u):
        return self.mem[self.root(u)]

    # グループの要素数
    def size(self, u):
        return -self.table[self.root(u)]

    def allmember(self):
        return [m for m in self.mem if m]

from collections import defaultdict

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

    res = []
    xy.sort()
    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 RotatingCalipers(xy):
    def dist(i, j):
        ix, iy = xy[i]
        jx, jy = xy[j]
        return (ix-jx)**2+(iy-jy)**2

    def vec(i):
        x0, y0 = xy[i]
        x1, y1 = xy[(i+1)%n]
        return x1-x0, y1-y0

    def outer(i, j):
        vix, viy = vec(i)
        vjx, vjy = vec(j)
        return vix*vjy-viy*vjx

    n = len(xy)
    if n < 2: return 0
    if n == 2: return dist(0, 1)**0.5
    res = 0
    i = xy.index(min(xy))
    j = xy.index(max(xy))
    si, sj = i, j
    while i != sj or j != si:
        res = max(res, dist(i, j))
        if outer(i, j) > 0: j = (j+1)%n
        else: i = (i+1)%n
    return res**0.5

n = II()
if n==0:
    print(1)
    exit()

ij2u = defaultdict(list)
xy = []
for u in range(n):
    x, y = LI()
    i, j = x//7, y//7
    xy.append((x, y))
    ij2u[i, j].append(u)

uf = UnionFind(n)
for i, j in ij2u:
    uu = ij2u[i, j]
    for u, v in zip(uu, uu[1:]): uf.merge(u, v)

def connect(si, sj, i, j):
    for u in ij2u[si, sj]:
        x, y = xy[u]
        for v in ij2u[i, j]:
            s, t = xy[v]
            if (x-s)**2+(y-t)**2 <= 100: return True
    return False

for si, sj in ij2u:
    for i in range(si, si+3):
        for j in range(sj-2 if i > si else sj+1, sj+3):
            if (i, j) not in ij2u: continue
            if connect(si, sj, i, j): uf.merge(ij2u[si, sj][0], ij2u[i, j][0])

ans = 0
for uu in uf.allmember():
    if len(uu) == 1: continue
    nxy = [xy[u] for u in uu]
    nxy = ConvexHull(nxy)
    ans = max(ans, RotatingCalipers(nxy))

print(ans+2)
0