結果

問題 No.2157 崖
ユーザー flygonflygon
提出日時 2022-12-09 23:22:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,042 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 176,480 KB
最終ジャッジ日時 2024-04-22 23:04:16
合計ジャッジ時間 10,125 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
176,480 KB
testcase_01 AC 48 ms
55,168 KB
testcase_02 AC 50 ms
54,912 KB
testcase_03 AC 62 ms
64,256 KB
testcase_04 AC 48 ms
55,040 KB
testcase_05 AC 64 ms
64,640 KB
testcase_06 AC 49 ms
55,424 KB
testcase_07 AC 66 ms
66,304 KB
testcase_08 AC 53 ms
60,544 KB
testcase_09 AC 58 ms
62,336 KB
testcase_10 AC 48 ms
55,168 KB
testcase_11 AC 64 ms
66,176 KB
testcase_12 AC 48 ms
54,912 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
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
dr = [[] for i in range(n)]
for i in range(1,n):
  for j in range(m):
    if j == 0:
      dr[i].append(0)
    else:  
      rr = bisect_right(d[i-1], d[i][j])
      dr[i].append(rr)

_ = [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)
    for j in range(1,m):
      new[j] = new[j-1]
      ll = bisect_left(d[i-1], max(1,dd[j]-mid))
      rr = dr[i][j]
      tmp = dp[rr-1] - dp[ll-1]
      new[j] += (tmp > 0)
    dp = new
  if dp[-1] == 0 :
    l = mid
  else:
    r = mid
ans = r
print(ans) if ans != 10**9+10 else print(-1)
0