結果
| 問題 |
No.2157 崖
|
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2022-12-12 04:16:22 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,660 bytes |
| コンパイル時間 | 393 ms |
| コンパイル使用メモリ | 82,200 KB |
| 実行使用メモリ | 111,624 KB |
| 最終ジャッジ日時 | 2024-11-06 04:23:59 |
| 合計ジャッジ時間 | 30,519 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 TLE * 1 |
ソースコード
def General_Binary_Increase_Search_Integer(L, R, cond, default=None):
""" 条件式が単調増加であるとき, 整数上で二部探索を行う.
L: 解の下限
R: 解の上限
cond: 条件(1変数関数, 広義単調増加を満たす)
default: Lで条件を満たさないときの返り値
"""
if not(cond(R)):
return default
if cond(L):
return L
R+=1
while R-L>1:
C=L+(R-L)//2
if cond(C):
R=C
else:
L=C
return R
#==================================================
class Product_List_2D:
def __init__(self, default, H, W):
""" H x W の直積リストを生成する. """
self.H=H
self.W=W
self.list=[default]*(H*W)
def __len__(self):
return self.H*self.W
def get(self, i, j):
if i<0:
i+=self.H
if j<0:
j+=self.W
return self.list[i*self.W+j]
def get_all(self):
return [self.list[i*self.W: (i+1)*self.W] for i in range(self.H)]
def projection_H(self, i):
if i<0:
i+=self.H
return self.list[i*self.W: (i+1)*self.W]
def set(self, i, j, value):
if i<0:
i+=self.H
if j<0:
j+=self.W
self.list[i*self.W+j]=value
def set_once(self, i, A):
if i<0:
i+=self.H
index=i*self.W
for j in range(self.W):
self.list[index]=A[j]
index+=1
def __getitem__(self, index):
return self.get(index[0], index[1])
def __setitem__(self, index, value):
self.set(index[0], index[1], value)
def __repr__(self):
return "[Product List 2D] : Height: {}, Width: {}".format(self.H, self.W)
#==================================================
def solve():
N,M=map(int,input().split())
D=Product_List_2D(0,N,M)
for i in range(N):
Di=list(map(int,input().split()))
Di.sort()
D.set_once(i, Di)
DP=Product_List_2D(0,N,M)
DP.set_once(0,[1]*M)
def check(X):
for i in range(1,N):
l=0; r=0; k=0
for j in range(M):
while r<M and D[i-1,r]<=D[i,j]:
k+=DP[i-1,r]
r+=1
while l<r and D[i,j]-D[i-1,l]>X:
k-=DP[i-1,l]
l+=1
DP[i,j]=1 if k else 0
return any(DP.projection_H(-1))
if not check(float("inf")):
return -1
return General_Binary_Increase_Search_Integer(0,10**9,check)
#==================================================
print(solve())
Kazun