結果

問題 No.2157 崖
ユーザー lloyzlloyz
提出日時 2024-01-05 20:44:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,754 ms / 6,000 ms
コード長 796 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 94,064 KB
最終ジャッジ日時 2024-01-05 20:44:19
合計ジャッジ時間 14,952 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,456 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 35 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 36 ms
53,460 KB
testcase_10 AC 35 ms
53,460 KB
testcase_11 AC 40 ms
59,248 KB
testcase_12 AC 36 ms
53,460 KB
testcase_13 AC 1,231 ms
89,584 KB
testcase_14 AC 469 ms
92,016 KB
testcase_15 AC 1,754 ms
90,864 KB
testcase_16 AC 1,738 ms
90,480 KB
testcase_17 AC 405 ms
90,224 KB
testcase_18 AC 409 ms
89,840 KB
testcase_19 AC 1,651 ms
92,656 KB
testcase_20 AC 557 ms
93,552 KB
testcase_21 AC 524 ms
94,064 KB
testcase_22 AC 386 ms
89,584 KB
testcase_23 AC 35 ms
53,460 KB
testcase_24 AC 56 ms
67,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
D = []
for _ in range(n):
    L = list(map(int, input().split()))
    L.sort()
    D.append(L)

def calc(val):
    DP = D[0].copy()
    for i in range(n - 1):
        NDP = []
        j = 0
        for curr in DP:
            while j < m:
                if D[i + 1][j] < curr:
                    j += 1
                elif D[i + 1][j] > curr + val:
                    break
                else:
                    NDP.append(D[i + 1][j])
                    j += 1
        if len(NDP) == 0:
            return False
        DP = NDP
    return True

l, r = -1, 10**9
if not calc(r):
    print(-1)
    exit()

while r - l > 1:
    mid = (l + r) // 2
    if calc(mid):
        r = mid
    else:
        l = mid
print(r)
0