結果
| 問題 | No.2157 崖 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-02 00:26:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 5,038 ms / 6,000 ms |
| コード長 | 1,828 bytes |
| 記録 | |
| コンパイル時間 | 336 ms |
| コンパイル使用メモリ | 82,100 KB |
| 実行使用メモリ | 100,012 KB |
| 最終ジャッジ日時 | 2025-12-02 00:27:36 |
| 合計ジャッジ時間 | 45,927 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
from sys import stdin,setrecursionlimit#,set_int_max_str_digits
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
# setrecursionlimit(2000000) # これこどふぉだと無理
# set_int_max_str_digits(200010)
mod = 998244353
ii = lambda :int(stdin.readline())
mi = lambda :map(int,stdin.readline().split())
li = lambda :list(mi())
gmi = lambda :map(lambda x: int(x) - 1, stdin.readline().split())
gi = lambda :list(map(lambda x: 0 if x == "." else 1,input())) # グリッド入力受け取り
py = lambda :print("Yes")
pn = lambda :print("No")
pf = lambda :print("First")
ps = lambda :print("Second")
pyn = lambda x: print("Yes") if x else print("No")
vec = [(1,0),(-1,0),(0,-1),(0,1)]
vec1 = [(1,0),(1,1),(0,1),(-1,1),(-1,0),(-1,-1),(0,-1),(1,-1)] #8方向
vec2 = [(1,1),(1,0),(0,-1),(-1,-1),(-1,0),(0,1)] # 六角形グリッド
inf = 10**18
from collections import defaultdict,deque
from heapq import heappop,heappush
# from random import randint
from itertools import permutations
n,m = mi()
d = [list(sorted(li())) for _ in range(n)]
# for i in d:
# print(i)
# print()
def solve(k):
dp = [1]*m
for i in range(1,n):
ndp = [0]*m
cnt = 0
l,r = 0,-1
for j,x in enumerate(d[i]):
while l < m and x - d[i-1][l] > k:
cnt -= dp[l]
l += 1
while r < m-1 and x >= d[i-1][r+1]:
r += 1
cnt += dp[r]
if cnt:
ndp[j] = 1
# if i == 1 and j == 0:
# print(l,r)
dp = ndp
#print(dp)
return sum(dp)
#print(solve(2))
ok = 10**9 + 1
ng = -1
while abs(ok-ng) > 1:
mid = (ok+ng)//2
if solve(mid):
ok = mid
else:
ng = mid
print(ok if ok < 10**9 + 1 else -1)