結果

問題 No.2612 Close the Distance
ユーザー chineristAC
提出日時 2024-01-19 23:15:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,464 ms / 3,000 ms
コード長 1,791 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 288,696 KB
最終ジャッジ日時 2024-10-01 01:18:16
合計ジャッジ時間 43,484 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import heappop,heappush
from collections import deque
import random
import bisect
from math import gcd


input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())



N = int(input())
xy = []
for _ in range(N):
    x,y = mi()
    xy.append(((x+y,x-y)))



def cond_2sq(tmp_xy,D):
    if not tmp_xy:
        return True
    x_min,x_max = min(x for x,y in tmp_xy),max(x for x,y in tmp_xy)
    y_min,y_max = min(y for x,y in tmp_xy),max(y for x,y in tmp_xy)

    """
    x_min,y_minを同時達成 or x_max,y_minを同時達成
    """
    for px,py in [(x_min,y_min),(x_max-D,y_min)]:
        tmp_x_min,tmp_x_max = x_max,x_min
        tmp_y_min,tmp_y_max = y_max,y_min
        for x,y in tmp_xy:
            if not px <= x <= px + D or not py <= y <= py + D:
                tmp_x_min = min(tmp_x_min,x)
                tmp_x_max = max(tmp_x_max,x)
                tmp_y_min = min(tmp_y_min,y)
                tmp_y_max = max(tmp_y_max,y)
        if (tmp_x_max-tmp_x_min) <= D and (tmp_y_max-tmp_y_min) <= D:
            return True
    return False

res = 10**10
#print("xy",xy)
for _ in range(4):
    x_min,y_min = min(x for x,y in xy),min(y for x,y in xy)
    #print(x_min,y_min)
    def cond_3sq(D):
        tmp_xy = []
        #print(x_min,y_min)
        for x,y in xy:
            if not x_min <= x <= x_min+D or not y_min <= y <= y_min+D:
                tmp_xy.append((x,y))
        #print(tmp_xy)
        return cond_2sq(tmp_xy,D)
    #print(cond_3sq(47))
    
    ok = res
    ng = -1
    while ok-ng>1:
        mid = (ok+ng)//2
        if cond_3sq(mid):
            ok = mid
        else:
            ng = mid
    res = ok

    xy = [(-y,x) for x,y in xy]

print(res)
        
0