結果

問題 No.96 圏外です。
コンテスト
ユーザー titia
提出日時 2026-07-19 05:36:08
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,258 ms / 5,000 ms
+ 149µs
コード長 3,017 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 245 ms
コンパイル使用メモリ 95,728 KB
実行使用メモリ 137,832 KB
最終ジャッジ日時 2026-07-19 05:36:21
合計ジャッジ時間 10,815 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

from collections import defaultdict

N=int(input())

if N==0:
    print(1)
    exit()

P=[list(map(int,input().split())) for i in range(N)]

for i in range(N):
    P[i][0]+=10000
    P[i][1]+=10000

# UnionFind

Group = [i for i in range(N)] # グループ分け
Nodes = [1]*(N) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

LIST=defaultdict(list)

for i in range(N):
    x,y=P[i]
    LIST[(x//10,y//10)].append(i)

for C in LIST:
    x,y=C
    X=[]

    if (x,y) in LIST:
        X+=LIST[x,y]

    if (x,y+1) in LIST:
        X+=LIST[x,y+1]

    if (x+1,y+1) in LIST:
        X+=LIST[x+1,y+1]

    if (x+1,y) in LIST:
        X+=LIST[x+1,y]

    if (x+1,y-1) in LIST:
        X+=LIST[x+1,y-1]

    #print(X)

    for i in range(len(X)):
        for j in range(i+1,len(X)):
            a,b=P[X[i]]
            c,d=P[X[j]]

            if (a-c)*(a-c)+(b-d)*(b-d)<=10*10:
                Union(X[i],X[j])

ANS=0
L=[[] for i in range(N)]

for i in range(N):
    L[find(i)].append(P[i])
    
from operator import itemgetter   
for i in range(N):
    if len(L[i])>100:
        P=L[i]

        P.sort(key=itemgetter(1)) # 一番左下の点から始める。
        P.sort(key=itemgetter(0))

        # 上側凸包と下側凸包
        Q1=[]
        Q2=[]
         
        def outer_product(x,y,z,w):
            return x*w-y*z
         
        for x,y in P:
            while True:
                if len(Q1)<2:
                    break
         
                s,t=Q1[-1]
                u,v=Q1[-2]
         
                if outer_product(u-s,v-t,x-u,y-v)<0:
                    Q1.pop()
                else:
                    break
         
            Q1.append((x,y))
         
            while True:
                if len(Q2)<2:
                    break
         
                s,t=Q2[-1]
                u,v=Q2[-2]
         
                if outer_product(u-s,v-t,x-u,y-v)>0:
                    Q2.pop()
                else:
                    break
         
            Q2.append((x,y))


        Q2.reverse()
        Q=Q1+Q2[1:] # 上側凸包と下側凸包を結んで凸包が完成

        for i in range(len(Q)):
            jx=i+len(Q)//2
            for j in range(jx-100,jx+100):
                a,b=Q[i]
                c,d=Q[j%len(Q)]

                ANS=max(ANS,(a-c)*(a-c)+(b-d)*(b-d))
    else:
        Q=L[i]

        for i in range(len(Q)):
            for j in range(i+1,len(Q)):
                a,b=Q[i]
                c,d=Q[j]

                ANS=max(ANS,(a-c)*(a-c)+(b-d)*(b-d))

print(ANS**(1/2)+2)

        
0