結果

問題 No.2157 崖
ユーザー KowerKoint2010KowerKoint2010
提出日時 2022-12-08 22:45:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,241 ms / 6,000 ms
コード長 763 bytes
コンパイル時間 492 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 96,512 KB
最終ジャッジ日時 2024-04-22 18:33:05
合計ジャッジ時間 35,290 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,352 KB
testcase_01 AC 38 ms
52,864 KB
testcase_02 AC 35 ms
52,480 KB
testcase_03 AC 41 ms
59,136 KB
testcase_04 AC 37 ms
52,352 KB
testcase_05 AC 43 ms
59,776 KB
testcase_06 AC 36 ms
52,992 KB
testcase_07 AC 56 ms
63,104 KB
testcase_08 AC 39 ms
52,608 KB
testcase_09 AC 39 ms
53,164 KB
testcase_10 AC 37 ms
52,224 KB
testcase_11 AC 52 ms
62,040 KB
testcase_12 AC 39 ms
52,480 KB
testcase_13 AC 2,397 ms
90,536 KB
testcase_14 AC 3,767 ms
94,568 KB
testcase_15 AC 2,765 ms
89,892 KB
testcase_16 AC 2,672 ms
89,900 KB
testcase_17 AC 2,562 ms
92,060 KB
testcase_18 AC 3,038 ms
92,340 KB
testcase_19 AC 3,114 ms
93,232 KB
testcase_20 AC 3,605 ms
95,708 KB
testcase_21 AC 4,241 ms
96,512 KB
testcase_22 AC 2,415 ms
91,960 KB
testcase_23 AC 37 ms
51,968 KB
testcase_24 AC 87 ms
77,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, map(int, input().split()))
d = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    d[i].sort()
ok = 10**9
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    bs = [True] * m
    for i in range(n-1):
        dp = [0] * (m+1)
        k1 = 0
        k2 = 0
        for j in range(m):
            if not bs[j]:
                continue
            while k1 < m and d[i+1][k1] - d[i][j] < 0:
                k1 += 1
            while k2 < m and d[i+1][k2] - d[i][j] <= mid:
                k2 += 1
            dp[k1] += 1
            dp[k2] -= 1
        for j in range(m):
            bs[j] = dp[j] > 0
            dp[j+1] += dp[j]
    if any(bs):
        ok = mid
    else:
        ng = mid
print(-1 if ok == 10**9 else ok)
0