結果

問題 No.2157 崖
ユーザー ああいいああいい
提出日時 2022-12-11 15:02:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,296 ms / 6,000 ms
コード長 756 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 94,592 KB
最終ジャッジ日時 2024-04-23 12:10:37
合計ジャッジ時間 12,566 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
51,968 KB
testcase_01 AC 35 ms
52,480 KB
testcase_02 AC 36 ms
52,608 KB
testcase_03 AC 33 ms
52,352 KB
testcase_04 AC 33 ms
52,224 KB
testcase_05 AC 33 ms
52,224 KB
testcase_06 AC 32 ms
52,352 KB
testcase_07 AC 33 ms
52,224 KB
testcase_08 AC 34 ms
51,968 KB
testcase_09 AC 34 ms
52,224 KB
testcase_10 AC 37 ms
52,096 KB
testcase_11 AC 37 ms
58,112 KB
testcase_12 AC 34 ms
52,352 KB
testcase_13 AC 898 ms
89,676 KB
testcase_14 AC 414 ms
93,312 KB
testcase_15 AC 1,217 ms
91,156 KB
testcase_16 AC 1,256 ms
90,880 KB
testcase_17 AC 376 ms
90,880 KB
testcase_18 AC 388 ms
90,624 KB
testcase_19 AC 1,296 ms
93,184 KB
testcase_20 AC 525 ms
94,336 KB
testcase_21 AC 530 ms
94,592 KB
testcase_22 AC 408 ms
90,368 KB
testcase_23 AC 38 ms
52,224 KB
testcase_24 AC 83 ms
73,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

N,M = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(N)]
for i in range(N):
    D[i].sort()
    
def calc(m):
    now = D[0].copy()
    for i in range(N - 1):
        nx = []
        tmp = D[i + 1]
        j = 0
        for a in now:
            while j < M:
                if tmp[j] < a:j += 1
                elif tmp[j] > a + m:break
                else:
                    nx.append(tmp[j])
                    j += 1
        if len(nx) == 0:return False
        else:
            now = nx
    return True

start = -1
end = 10 ** 9
if calc(end) == False:
    print(-1)
    exit()

while end - start > 1:
    mid = end + start >> 1
    if calc(mid):
        end = mid
    else:
        start = mid
print(end)
0