結果
| 問題 | 
                            No.2157 崖
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kemuniku
                         | 
                    
| 提出日時 | 2022-12-09 22:09:08 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,042 bytes | 
| コンパイル時間 | 236 ms | 
| コンパイル使用メモリ | 82,344 KB | 
| 実行使用メモリ | 117,240 KB | 
| 最終ジャッジ日時 | 2024-10-14 22:06:01 | 
| 合計ジャッジ時間 | 16,177 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 TLE * 2 -- * 10 | 
ソースコード
#https://aotamasaki.hatenablog.com/entry/meguru_bisect
import bisect
def is_ok(arg):
    now = D[0]
    for i in range(1,N):
        next = []
        for j in range(M):
            ind = bisect.bisect(now,D[i][j])
            if ind != 0:
                if D[i][j]-now[ind-1] <= arg:
                    next.append(D[i][j])
        now = next
        if len(now) == 0:
            return False
    return True
def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok
N,M = map(int,input().split())
D = [list(sorted(list(map(int,input().split())))) for i in range(N)]
x = meguru_bisect(-1,10**9+1)
if x == 10**9+1:
    print(-1)
else:
    print(x)
            
            
            
        
            
kemuniku