結果

問題 No.2157 崖
ユーザー mkawa2mkawa2
提出日時 2022-12-09 21:50:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,672 ms / 6,000 ms
コード長 1,389 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,216 KB
実行使用メモリ 96,968 KB
最終ジャッジ日時 2024-04-22 21:45:01
合計ジャッジ時間 17,643 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,736 KB
testcase_01 AC 40 ms
52,480 KB
testcase_02 AC 40 ms
52,480 KB
testcase_03 AC 40 ms
52,736 KB
testcase_04 AC 39 ms
53,120 KB
testcase_05 AC 42 ms
52,864 KB
testcase_06 AC 39 ms
52,864 KB
testcase_07 AC 47 ms
59,520 KB
testcase_08 AC 43 ms
52,352 KB
testcase_09 AC 47 ms
53,248 KB
testcase_10 AC 42 ms
52,608 KB
testcase_11 AC 47 ms
59,904 KB
testcase_12 AC 43 ms
52,736 KB
testcase_13 AC 1,265 ms
89,728 KB
testcase_14 AC 1,672 ms
94,356 KB
testcase_15 AC 1,435 ms
90,496 KB
testcase_16 AC 1,663 ms
90,560 KB
testcase_17 AC 1,160 ms
92,672 KB
testcase_18 AC 1,149 ms
92,288 KB
testcase_19 AC 1,434 ms
92,432 KB
testcase_20 AC 1,546 ms
96,880 KB
testcase_21 AC 1,536 ms
96,968 KB
testcase_22 AC 1,395 ms
92,008 KB
testcase_23 AC 39 ms
52,864 KB
testcase_24 AC 53 ms
68,100 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 bisect

def binary_search(l, r, 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):
    now = dd[0]
    for ds in dd[1:]:
        i = 0
        pre, now = now, []
        for d in ds:
            while i < len(pre) and pre[i] < d-m: i += 1
            if i == len(pre): break
            if pre[i] <= d: now.append(d)
        if not now: return False
    return True

n, m = LI()
dd = LLI(n)
for i in range(n): dd[i].sort()

ans = binary_search(0, 10**9, True)
if ans == 10**9: ans = -1

print(ans)
0