結果

問題 No.1998 Manhattan Restaurant
ユーザー mkawa2mkawa2
提出日時 2022-07-01 23:44:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 1,660 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 84,388 KB
最終ジャッジ日時 2023-08-17 11:31:39
合計ジャッジ時間 8,622 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,260 KB
testcase_01 AC 71 ms
71,112 KB
testcase_02 AC 69 ms
71,144 KB
testcase_03 AC 69 ms
71,148 KB
testcase_04 AC 69 ms
71,140 KB
testcase_05 AC 71 ms
70,956 KB
testcase_06 AC 102 ms
76,692 KB
testcase_07 AC 149 ms
77,472 KB
testcase_08 AC 146 ms
77,140 KB
testcase_09 AC 150 ms
77,080 KB
testcase_10 AC 109 ms
76,516 KB
testcase_11 AC 87 ms
75,912 KB
testcase_12 AC 78 ms
75,572 KB
testcase_13 AC 89 ms
75,620 KB
testcase_14 AC 106 ms
76,648 KB
testcase_15 AC 280 ms
83,684 KB
testcase_16 AC 205 ms
81,628 KB
testcase_17 AC 212 ms
82,660 KB
testcase_18 AC 242 ms
81,444 KB
testcase_19 AC 261 ms
82,252 KB
testcase_20 AC 261 ms
83,644 KB
testcase_21 AC 314 ms
84,016 KB
testcase_22 AC 331 ms
84,388 KB
testcase_23 AC 327 ms
84,144 KB
testcase_24 AC 331 ms
83,988 KB
testcase_25 AC 154 ms
78,384 KB
testcase_26 AC 245 ms
82,044 KB
testcase_27 AC 248 ms
80,888 KB
testcase_28 AC 244 ms
82,228 KB
testcase_29 AC 222 ms
80,756 KB
testcase_30 AC 256 ms
83,564 KB
testcase_31 AC 240 ms
83,232 KB
testcase_32 AC 158 ms
78,328 KB
testcase_33 AC 208 ms
81,512 KB
testcase_34 AC 239 ms
82,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

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

from bisect import *

n = II()
# ii,jj=set(),set()
il = jl = inf
ir = jr = -inf
ij = []
for _ in range(n):
    x, y = LI()
    i = x+y
    j = x-y
    ij.append((i, j))
    il = min(il, i)
    ir = max(ir, i)
    jl = min(jl, j)
    jr = max(jr, j)

def binary_search(l, r, ok, minimize):
    if minimize: l -= 1
    else: r += 1
    while l+1 < r:
        m = (l+r)//2
        if ok(m) ^ minimize: l = m
        else: r = m
    if minimize: return r
    return l

def ok(m):
    i1, j1 = il+m, jl+m
    i2, j2 = ir-m, jr-m
    # print(m, i1, j1, i2, j2)
    ng1 = ng2 = False
    for i, j in ij:
        d = min(max(abs(i-i1), abs(j-j1)), max(abs(i-i2), abs(j-j2)))
        if d > m: ng1 = True
        d = min(max(abs(i-i1), abs(j-j2)), max(abs(i-i2), abs(j-j1)))
        if d > m: ng2 = True
        if ng1 & ng2: return False
    return True

r = max((ir-il)//2, (jr-jl)//2)
# pDB(r)
ans = binary_search(0, r, ok, True)

print(ans)
0