結果

問題 No.96 圏外です。
ユーザー mkawa2mkawa2
提出日時 2023-07-12 18:42:39
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 3,601 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 87,392 KB
実行使用メモリ 152,732 KB
最終ジャッジ日時 2023-10-12 09:04:00
合計ジャッジ時間 33,834 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
72,868 KB
testcase_01 AC 100 ms
72,984 KB
testcase_02 AC 114 ms
72,832 KB
testcase_03 AC 97 ms
72,576 KB
testcase_04 AC 178 ms
81,200 KB
testcase_05 AC 205 ms
81,384 KB
testcase_06 AC 231 ms
82,316 KB
testcase_07 AC 271 ms
82,928 KB
testcase_08 AC 325 ms
84,680 KB
testcase_09 AC 398 ms
87,988 KB
testcase_10 AC 455 ms
90,232 KB
testcase_11 AC 517 ms
92,504 KB
testcase_12 AC 885 ms
107,512 KB
testcase_13 RE -
testcase_14 AC 867 ms
106,920 KB
testcase_15 AC 978 ms
113,264 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 1,229 ms
130,980 KB
testcase_19 RE -
testcase_20 AC 1,745 ms
152,732 KB
testcase_21 AC 621 ms
123,360 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(1000005)
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 << 63)-1
md = 10**9+7
# md = 998244353

from collections import defaultdict
from bisect import bisect_left

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 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 < 2:
    print(n+1)
    exit()

x2y = defaultdict(list)
xy2u={}
xy=[]
for u in range(n):
    x, y = LI()
    x2y[x].append(y)
    xy2u[x,y]=u
    xy.append((x,y))

# d2+w2 <= 100
# w<=sqrt(100-d2)
pre=[]
uf=UnionFind(n)
for x in sorted(x2y):
    x2y[x].sort()
    for y,q in zip(x2y[x],x2y[x][1:]):
        if q-y>10:continue
        uf.merge(xy2u[x,y],xy2u[x,q])
    for p in pre[::-1]:
        d=x-p
        if d>10:break
        w=int((100-d**2)**0.5)
        yy=x2y[p]
        for y in x2y[x]:
            l=bisect_left(yy,y-w)
            u=xy2u[x,y]
            for q in yy[l:]:
                if q>y+w:break
                v=xy2u[p,q]
                uf.merge(u,v)
    pre.append(x)

ans=2
for uu in uf.mem:
    if len(uu)<2:continue
    cur=ConvexHull([xy[u] for u in uu])
    ans=max(ans,RotatingCalipers(cur)+2)

print(ans)
0