結果
問題 | No.2436 Min Diff Distance |
ユーザー | chineristAC |
提出日時 | 2023-08-18 22:56:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,354 ms / 2,000 ms |
コード長 | 2,228 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 82,132 KB |
実行使用メモリ | 130,748 KB |
最終ジャッジ日時 | 2024-11-28 09:22:54 |
合計ジャッジ時間 | 19,766 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,864 KB |
testcase_01 | AC | 44 ms
52,992 KB |
testcase_02 | AC | 42 ms
52,736 KB |
testcase_03 | AC | 1,336 ms
129,472 KB |
testcase_04 | AC | 1,352 ms
129,332 KB |
testcase_05 | AC | 1,354 ms
129,072 KB |
testcase_06 | AC | 1,354 ms
129,184 KB |
testcase_07 | AC | 1,336 ms
128,712 KB |
testcase_08 | AC | 1,336 ms
129,332 KB |
testcase_09 | AC | 41 ms
53,248 KB |
testcase_10 | AC | 44 ms
52,608 KB |
testcase_11 | AC | 635 ms
122,252 KB |
testcase_12 | AC | 586 ms
122,892 KB |
testcase_13 | AC | 895 ms
109,832 KB |
testcase_14 | AC | 289 ms
83,348 KB |
testcase_15 | AC | 1,319 ms
130,748 KB |
testcase_16 | AC | 660 ms
97,216 KB |
testcase_17 | AC | 1,110 ms
113,628 KB |
testcase_18 | AC | 1,070 ms
119,852 KB |
testcase_19 | AC | 1,176 ms
113,764 KB |
testcase_20 | AC | 848 ms
100,484 KB |
testcase_21 | AC | 440 ms
88,384 KB |
testcase_22 | AC | 291 ms
83,024 KB |
ソースコード
import sys from itertools import permutations from heapq import * input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) class SegmentTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num self.size = n for i in range(n): self.tree[self.num + i] = init_val[i] for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): k += self.num self.tree[k] = self.segfunc(self.tree[k],x) while k > 1: k >>= 1 self.tree[k] = self.segfunc(self.tree[2*k], self.tree[2*k+1]) def query(self, l, r): if r==self.size: r = self.num res = self.ide_ele l += self.num r += self.num right = [] while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: right.append(self.tree[r-1]) l >>= 1 r >>= 1 for e in right[::-1]: res = self.segfunc(res,e) return res N = int(input()) X,Y = [-1] * N,[-1] * N for i in range(N): X[i],Y[i] = mi() X[i],Y[i] = X[i]-1,Y[i]-1 max_d = [0] * N min_d = [2*N+100] * N idx = [i for i in range(N)] idx.sort(key=lambda i:X[i]) for _ in range(2): for _ in range(2): M = max(X[i]+Y[i] for i in range(N)) for i in range(N): max_d[i] = max(max_d[i],M-(X[i]+Y[i])) #print(idx) seg = SegmentTree([5*N+100]*N,min,5*N+100) for i in idx: tmp = seg.query(Y[i],N) - Y[i] + X[i] min_d[i] = min(min_d[i],tmp) seg.update(Y[i],Y[i]-X[i]) Y = [N-1-Y[i] for i in range(N)] X = [N-1-X[i] for i in range(N)] idx = idx[::-1] ans = 10**100 for i in range(N): ans = min(ans,max_d[i]-min_d[i]) #print(max_d,min_d) P = [max_d[i]-min_d[i] for i in range(N)] #print(P) print(ans)