結果

問題 No.2157 崖
ユーザー rlangevinrlangevin
提出日時 2024-01-23 12:05:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,586 ms / 6,000 ms
コード長 829 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 94,192 KB
最終ジャッジ日時 2024-01-23 12:05:24
合計ジャッジ時間 15,643 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 37 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 37 ms
53,460 KB
testcase_10 AC 36 ms
53,460 KB
testcase_11 AC 45 ms
61,472 KB
testcase_12 AC 37 ms
53,460 KB
testcase_13 AC 2,143 ms
91,248 KB
testcase_14 AC 493 ms
92,016 KB
testcase_15 AC 2,242 ms
91,888 KB
testcase_16 AC 2,103 ms
91,504 KB
testcase_17 AC 430 ms
90,608 KB
testcase_18 AC 428 ms
90,352 KB
testcase_19 AC 2,586 ms
94,064 KB
testcase_20 AC 532 ms
93,936 KB
testcase_21 AC 545 ms
94,192 KB
testcase_22 AC 406 ms
89,968 KB
testcase_23 AC 38 ms
53,460 KB
testcase_24 AC 63 ms
73,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
D = []
for i in range(N):
    D.append(list(map(int, input().split())))
    D[i].sort()

def check(m):
    pre = [1] * M
    Dpre = D[0]
    for i in range(1, N):
        dp = [0] * M
        Di = D[i]
        now = 0
        for j in range(M):
            while now < M:
                if Di[j] < Dpre[now]:
                    break
                if pre[now] and Dpre[now] <= Di[j] <= Dpre[now] + m:
                    dp[j] = 1
                    break
                now += 1
        dp, pre = pre, dp
        Dpre, Di = Di, Dpre
    return sum(pre)  
    
yes = 10 ** 9 + 5
no = -1
if not check(yes):
    print(-1)
    exit()

while yes - no != 1:
    mid = (yes + no)//2
    if check(mid):
        yes = mid
    else:
        no = mid
print(yes)
0