結果

問題 No.2157 崖
ユーザー tassei903tassei903
提出日時 2022-12-09 22:20:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 5,012 ms / 6,000 ms
コード長 1,121 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 82,132 KB
実行使用メモリ 103,352 KB
最終ジャッジ日時 2024-04-22 22:31:27
合計ジャッジ時間 43,697 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
54,364 KB
testcase_01 AC 36 ms
55,496 KB
testcase_02 AC 38 ms
54,624 KB
testcase_03 AC 43 ms
62,288 KB
testcase_04 AC 36 ms
54,980 KB
testcase_05 AC 42 ms
61,748 KB
testcase_06 AC 39 ms
55,396 KB
testcase_07 AC 48 ms
65,604 KB
testcase_08 AC 43 ms
55,224 KB
testcase_09 AC 41 ms
55,848 KB
testcase_10 AC 38 ms
55,780 KB
testcase_11 AC 49 ms
65,400 KB
testcase_12 AC 37 ms
54,392 KB
testcase_13 AC 4,659 ms
93,812 KB
testcase_14 AC 4,210 ms
100,416 KB
testcase_15 AC 3,907 ms
92,744 KB
testcase_16 AC 3,899 ms
92,892 KB
testcase_17 AC 3,404 ms
96,296 KB
testcase_18 AC 3,119 ms
96,016 KB
testcase_19 AC 5,012 ms
98,236 KB
testcase_20 AC 4,277 ms
103,352 KB
testcase_21 AC 4,737 ms
102,124 KB
testcase_22 AC 2,945 ms
95,212 KB
testcase_23 AC 36 ms
54,448 KB
testcase_24 AC 87 ms
77,328 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**9+1
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**9+1:
    print(-1)
else:
    print(ok)
0