結果

問題 No.2157 崖
ユーザー flygonflygon
提出日時 2022-12-09 23:40:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 991 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 81,944 KB
実行使用メモリ 164,896 KB
最終ジャッジ日時 2024-04-22 23:18:25
合計ジャッジ時間 16,131 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,632 KB
testcase_01 AC 45 ms
55,168 KB
testcase_02 AC 44 ms
54,656 KB
testcase_03 AC 53 ms
63,360 KB
testcase_04 AC 49 ms
54,656 KB
testcase_05 AC 55 ms
63,872 KB
testcase_06 AC 44 ms
54,944 KB
testcase_07 AC 57 ms
64,896 KB
testcase_08 AC 46 ms
55,680 KB
testcase_09 AC 48 ms
55,552 KB
testcase_10 AC 43 ms
54,528 KB
testcase_11 AC 57 ms
64,896 KB
testcase_12 AC 44 ms
55,040 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 AC 5,434 ms
143,888 KB
testcase_18 AC 5,600 ms
144,024 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

n,m = map(int,input().split())
d  = [[-1] + list(map(int,input().split())) for i in range(n)]
for i in range(n):
  d[i].sort()
  
m+= 1
_ = [i for i in range(m)]
l = -1
r = 10**9+10
while r-l > 1:
  mid = (r+l)//2
  dp = _[::1]
  for i in range(1, n):
    dd = d[i]
    new = [0]*(m)
    ll = 0
    rr = 0
    for j in range(1,m):
      bot =max(1, d[i][j] - mid)
      top = d[i][j]
      while ll < m-1 and d[i-1][ll+1] < bot:
        ll += 1
      while rr < m-1 and d[i-1][rr+1] <= top:
        rr += 1
        if rr == m: break
      tmp = dp[rr] - dp[ll]
      new[j] = new[j-1] + tmp
    dp = new
  if dp[-1] == 0 :
    l = mid
  else:
    r = mid
ans = r
print(ans) if ans != 10**9+10 else print(-1)
0