結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,352 KB
testcase_01 AC 43 ms
52,352 KB
testcase_02 AC 42 ms
52,608 KB
testcase_03 AC 43 ms
52,480 KB
testcase_04 AC 41 ms
52,352 KB
testcase_05 AC 50 ms
58,880 KB
testcase_06 AC 41 ms
52,480 KB
testcase_07 AC 67 ms
65,792 KB
testcase_08 AC 46 ms
58,112 KB
testcase_09 AC 48 ms
58,752 KB
testcase_10 AC 43 ms
52,352 KB
testcase_11 AC 59 ms
63,232 KB
testcase_12 AC 42 ms
52,096 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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)
0