結果

問題 No.2543 Many Meetings
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-11-24 22:35:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 850 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 160,752 KB
最終ジャッジ日時 2023-11-24 22:35:50
合計ジャッジ時間 19,196 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,604 KB
testcase_01 AC 40 ms
55,604 KB
testcase_02 AC 41 ms
55,604 KB
testcase_03 AC 735 ms
160,236 KB
testcase_04 AC 712 ms
160,752 KB
testcase_05 AC 739 ms
160,240 KB
testcase_06 AC 752 ms
160,188 KB
testcase_07 AC 714 ms
160,248 KB
testcase_08 AC 762 ms
160,192 KB
testcase_09 AC 746 ms
160,220 KB
testcase_10 AC 770 ms
160,212 KB
testcase_11 AC 755 ms
160,216 KB
testcase_12 AC 737 ms
160,196 KB
testcase_13 AC 672 ms
137,980 KB
testcase_14 AC 398 ms
111,308 KB
testcase_15 AC 347 ms
111,048 KB
testcase_16 AC 582 ms
127,876 KB
testcase_17 AC 671 ms
138,220 KB
testcase_18 AC 694 ms
141,508 KB
testcase_19 AC 641 ms
136,172 KB
testcase_20 AC 667 ms
137,984 KB
testcase_21 AC 850 ms
154,016 KB
testcase_22 AC 634 ms
138,344 KB
testcase_23 AC 72 ms
70,612 KB
testcase_24 AC 52 ms
64,168 KB
testcase_25 AC 57 ms
66,500 KB
testcase_26 AC 58 ms
68,568 KB
testcase_27 AC 68 ms
70,592 KB
testcase_28 AC 477 ms
134,544 KB
testcase_29 AC 226 ms
95,504 KB
testcase_30 AC 218 ms
95,768 KB
testcase_31 AC 186 ms
90,580 KB
testcase_32 AC 443 ms
129,572 KB
testcase_33 AC 41 ms
55,604 KB
testcase_34 AC 40 ms
55,604 KB
testcase_35 AC 43 ms
55,604 KB
testcase_36 AC 40 ms
55,604 KB
testcase_37 AC 40 ms
55,604 KB
testcase_38 AC 40 ms
55,604 KB
testcase_39 AC 40 ms
55,604 KB
testcase_40 AC 39 ms
55,604 KB
testcase_41 AC 39 ms
55,604 KB
testcase_42 AC 40 ms
55,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n,k = map(int,input().split())
LR = [list(map(int,input().split())) for i in range(n)]

par = [-1]*n

sLR = [[l,r,i] for i,(l,r) in enumerate(LR)]
sLR.sort(key=lambda x: x[1])
wait = deque([])
for l,r,ind in sLR:

    while wait and wait[0][1] <= l:
        bl,br,bind = wait.popleft()
        par[bind] = ind
    
    wait.append([l,r,ind])


doubling = [[-1]*n for i in range(20)]
doubling[0] = par[:]

for i in range(1,20):

    for j in range(n):
        pos = doubling[i-1][j]
        if pos == -1:
            continue
        pos = doubling[i-1][pos]
        doubling[i][j] = pos


ans = 10**10

for i in range(n):

    res = k-1
    now = i
    for j in range(20)[::-1]:
        if 1<<j <= res and now != -1:
            now = doubling[j][now]
            res -= 1<<j
    if now != -1:
        ans = min(ans,LR[now][1]-LR[i][0])


if ans == 10**10:
    ans = -1

print(ans)
0