結果

問題 No.2157 崖
ユーザー achapiachapi
提出日時 2022-12-09 22:29:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,079 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 81,880 KB
実行使用メモリ 95,152 KB
最終ジャッジ日時 2024-04-22 22:36:47
合計ジャッジ時間 10,196 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,120 KB
testcase_01 AC 45 ms
58,752 KB
testcase_02 AC 41 ms
52,736 KB
testcase_03 AC 41 ms
52,608 KB
testcase_04 AC 41 ms
52,352 KB
testcase_05 AC 44 ms
57,848 KB
testcase_06 AC 41 ms
52,736 KB
testcase_07 AC 46 ms
59,008 KB
testcase_08 WA -
testcase_09 AC 48 ms
59,392 KB
testcase_10 AC 40 ms
52,480 KB
testcase_11 WA -
testcase_12 AC 44 ms
58,368 KB
testcase_13 WA -
testcase_14 AC 748 ms
93,824 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 670 ms
91,520 KB
testcase_18 AC 653 ms
91,264 KB
testcase_19 WA -
testcase_20 AC 889 ms
94,976 KB
testcase_21 AC 847 ms
95,152 KB
testcase_22 AC 631 ms
91,136 KB
testcase_23 AC 40 ms
52,528 KB
testcase_24 AC 88 ms
76,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
s=[list(map(int,input().split()))for i in range(n)]
for i in range(n):s[i].sort()
from bisect import*
def le(a, x):
    i = bisect_right(a, x)
    if i:return a[i-1]
    return -1
def ge(a, x):
    i = bisect_left(a, x)
    if i != len(a):return a[i]
    return -1
def validate(x):
    ans=10**18
    for i in range(m):
        c=s[0][i]
        k=0
        for j in range(1,n):
            r=le(s[j],c+x)
            if r==-1 or r<c:break
            k=max(k,r-c)
            c=r
        else:ans=min(ans,k)
    if ans==10**18:return True
    else:return False
def binarysearch(left=-1,right=10**18,r=0):
    while left<=right:
        mid=(left+right)//2
        if validate(mid):r=mid;left=mid+1
        else:right=mid-1
    return r
c=binarysearch()
if c==10**18:
    ans=10**18
    for i in range(m):
        c=s[0][i]
        k=0
        for j in range(1,n):
            r=ge(s[j],c)
            if r==-1:break
            k=max(k,r-c)
            c=r
        else:ans=min(ans,k)
    if ans==10**18:print(-1)
    else:print(ans)
else:print(c+1)
0