結果

問題 No.2436 Min Diff Distance
ユーザー ShirotsumeShirotsume
提出日時 2023-08-18 22:17:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,980 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 161,352 KB
最終ジャッジ日時 2023-08-18 22:18:30
合計ジャッジ時間 5,468 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
74,324 KB
testcase_01 AC 114 ms
74,380 KB
testcase_02 AC 114 ms
74,268 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 116 ms
74,088 KB
testcase_10 AC 126 ms
74,484 KB
testcase_11 AC 438 ms
139,328 KB
testcase_12 AC 443 ms
139,740 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 TLE -
testcase_16 WA -
testcase_17 TLE -
testcase_18 WA -
testcase_19 TLE -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

n = ii()

XY = [li() + [i] for i in range(n)]

mini = [inf] * n

XY.sort(key = lambda x: (x[0], x[1]))
for i in range(n):
    x1, y1, ind1 = XY[i]
    if i > 0:
        x2, y2, _ = XY[i - 1]
        mini[ind1] = min(mini[ind1], abs(x1 - x2) + abs(y1 - y2))
    if i < n - 1:
        x2, y2, _ = XY[i + 1]
        mini[ind1] = min(mini[ind1], abs(x1 - x2) + abs(y1 - y2))

XY.sort(key = lambda x: (x[1], x[0]))

for i in range(n):
    x1, y1, ind1 = XY[i]
    if i > 0:
        x2, y2, _ = XY[i - 1]
        mini[ind1] = min(mini[ind1], abs(x1 - x2) + abs(y1 - y2))
    if i < n - 1:
        x2, y2, _ = XY[i + 1]
        mini[ind1] = min(mini[ind1], abs(x1 - x2) + abs(y1 - y2))


XY.sort(key = lambda x: (x[0] + x[1]))
for i in range(n):
    x1, y1, ind1 = XY[i]
    if i > 0:
        x2, y2, _ = XY[i - 1]
        mini[ind1] = min(mini[ind1], abs(x1 - x2) + abs(y1 - y2))
    if i < n - 1:
        x2, y2, _ = XY[i + 1]
        mini[ind1] = min(mini[ind1], abs(x1 - x2) + abs(y1 - y2))


XY.sort(key = lambda x: (x[0] - x[1]))
for i in range(n):
    x1, y1, ind1 = XY[i]
    if i > 0:
        x2, y2, _ = XY[i - 1]
        mini[ind1] = min(mini[ind1], abs(x1 - x2) + abs(y1 - y2))
    if i < n - 1:
        x2, y2, _ = XY[i + 1]
        mini[ind1] = min(mini[ind1], abs(x1 - x2) + abs(y1 - y2))



xmax = -inf
xmin = inf
ymax = -inf
ymin = inf
for i in range(n):
    x, y, ind = XY[i]
    XY[i] = [x + y, x - y, ind]
    xmax = max(xmax, x + y)
    xmin = min(xmin, x + y)
    ymax = max(ymax, x - y)
    ymin = min(ymin, x - y)
maxi = [0] * n
for i in range(n):
    x, y, ind = XY[i]
    maxi[ind] = max(xmax - x, x - xmin, ymax - y, y - ymin)

ans = inf        
for i in range(n):
    ans = min(ans, maxi[i] - mini[i])
print(ans)
0