結果

問題 No.2157 崖
ユーザー flygonflygon
提出日時 2022-12-09 23:42:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,455 ms / 6,000 ms
コード長 1,023 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 98,480 KB
最終ジャッジ日時 2024-04-22 23:19:19
合計ジャッジ時間 39,706 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
55,848 KB
testcase_01 AC 38 ms
56,548 KB
testcase_02 AC 38 ms
55,448 KB
testcase_03 AC 44 ms
64,712 KB
testcase_04 AC 37 ms
55,748 KB
testcase_05 AC 45 ms
64,640 KB
testcase_06 AC 38 ms
55,948 KB
testcase_07 AC 51 ms
66,356 KB
testcase_08 AC 41 ms
55,908 KB
testcase_09 AC 40 ms
57,720 KB
testcase_10 AC 43 ms
56,556 KB
testcase_11 AC 55 ms
65,720 KB
testcase_12 AC 39 ms
55,984 KB
testcase_13 AC 3,567 ms
91,336 KB
testcase_14 AC 4,103 ms
96,452 KB
testcase_15 AC 3,456 ms
91,908 KB
testcase_16 AC 3,558 ms
91,124 KB
testcase_17 AC 3,413 ms
93,912 KB
testcase_18 AC 3,498 ms
93,724 KB
testcase_19 AC 4,455 ms
94,840 KB
testcase_20 AC 3,485 ms
98,480 KB
testcase_21 AC 4,064 ms
98,472 KB
testcase_22 AC 3,176 ms
92,980 KB
testcase_23 AC 38 ms
55,380 KB
testcase_24 AC 77 ms
77,952 KB
権限があれば一括ダウンロードができます

ソースコード

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):
      new[j] = new[j-1]
      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]
      if tmp > 0:
        new[j] += 1
    dp = new
  if dp[-1] == 0 :
    l = mid
  else:
    r = mid
ans = r
print(ans) if ans != 10**9+10 else print(-1)
0