結果

問題 No.2157 崖
ユーザー tassei903tassei903
提出日時 2022-12-09 22:18:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 5,998 ms / 6,000 ms
コード長 1,119 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 104,556 KB
最終ジャッジ日時 2024-04-22 22:26:52
合計ジャッジ時間 51,252 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,016 KB
testcase_01 AC 44 ms
54,144 KB
testcase_02 AC 44 ms
54,016 KB
testcase_03 AC 50 ms
61,568 KB
testcase_04 AC 42 ms
53,888 KB
testcase_05 AC 50 ms
61,440 KB
testcase_06 AC 43 ms
53,888 KB
testcase_07 AC 55 ms
63,872 KB
testcase_08 AC 48 ms
54,400 KB
testcase_09 AC 46 ms
54,784 KB
testcase_10 AC 43 ms
54,144 KB
testcase_11 AC 57 ms
64,896 KB
testcase_12 AC 44 ms
53,888 KB
testcase_13 AC 4,999 ms
93,312 KB
testcase_14 AC 4,962 ms
101,100 KB
testcase_15 AC 4,643 ms
93,156 KB
testcase_16 AC 5,063 ms
92,952 KB
testcase_17 AC 4,142 ms
97,108 KB
testcase_18 AC 3,946 ms
96,668 KB
testcase_19 AC 5,998 ms
98,340 KB
testcase_20 AC 5,076 ms
104,556 KB
testcase_21 AC 5,131 ms
103,680 KB
testcase_22 AC 4,002 ms
96,000 KB
testcase_23 AC 42 ms
53,888 KB
testcase_24 AC 95 ms
77,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

n, m = na()
a = [sorted(na()) for i in range(n)]
if n == 1:
    print(0)
    exit()
ok = 10**10
ng = -1
from collections import deque

while ok-ng > 1:
    d = ok+ng>>1
    dp = [1] * m
    for i in range(n-1):
        k = 0
        dq = deque()
        ndp = [0] * m
        dp, ndp = ndp, dp
        for j in range(m):
            while k < m and a[i+1][k] <= a[i][j] + d:
                dq.append(k)
                k += 1

            while dq and a[i+1][dq[0]] < a[i][j]:
                dq.popleft()
            #print(dq)
            if ndp[j]:
                while dq:
                    dp[dq.popleft()] = 1
        #print(dp)
    #print(d, dp)
    if sum(dp):
        ok = d
    else:
        ng = d
if ok == 10**10:
    print(-1)
else:
    print(ok)
0