結果

問題 No.2157 崖
ユーザー iseeisee
提出日時 2022-12-10 01:06:18
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,040 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 102,980 KB
最終ジャッジ日時 2024-04-22 23:33:36
合計ジャッジ時間 44,279 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,420 KB
testcase_01 AC 40 ms
53,352 KB
testcase_02 AC 37 ms
53,080 KB
testcase_03 AC 44 ms
60,188 KB
testcase_04 AC 40 ms
53,136 KB
testcase_05 AC 44 ms
59,556 KB
testcase_06 AC 44 ms
53,104 KB
testcase_07 AC 48 ms
62,156 KB
testcase_08 AC 39 ms
52,200 KB
testcase_09 AC 40 ms
52,932 KB
testcase_10 AC 38 ms
52,824 KB
testcase_11 AC 54 ms
63,160 KB
testcase_12 AC 41 ms
52,224 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 AC 5,458 ms
92,624 KB
testcase_16 AC 5,878 ms
93,568 KB
testcase_17 AC 5,601 ms
93,204 KB
testcase_18 AC 5,002 ms
93,184 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    # 入力
    N, M = map(int, input().split())
    if N == 1:
        print(0)
        return
    D = [sorted(list(map(int, input().split()))) for _ in range(N)]
    # 計算・出力
    def isOK(d):
        dp = [True]*M
        for i in range(1, N):
            dp0 = [False]*M
            l = 0
            r = 0
            bool = 0
            for j in range(M):
                while r < M and D[i-1][r] <= D[i][j]:
                    bool += 1 if dp[r] else 0
                    r += 1
                while l < M and D[i-1][l] < D[i][j] - d:
                    bool -= 1 if dp[l] else 0
                    l += 1
                dp0[j] = (bool > 0)
            dp = dp0
        return any(dp)
        
    ng = -1
    ok = 10**9
    while abs(ng-ok) > 1:
        mid = (ok+ng)//2
        if isOK(mid) : # ここ頑張る
            ok = mid
        else:
            ng = mid
    print(ok if ok != 10**9 else -1)

if __name__ == "__main__":
    main()
0