結果

問題 No.2543 Many Meetings
ユーザー rlangevinrlangevin
提出日時 2023-11-25 20:38:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,336 ms / 2,000 ms
コード長 915 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 135,008 KB
最終ジャッジ日時 2023-11-25 20:39:08
合計ジャッジ時間 28,393 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 34 ms
53,460 KB
testcase_03 AC 1,313 ms
135,008 KB
testcase_04 AC 1,315 ms
135,008 KB
testcase_05 AC 1,323 ms
135,008 KB
testcase_06 AC 1,305 ms
135,008 KB
testcase_07 AC 1,293 ms
134,880 KB
testcase_08 AC 1,322 ms
135,008 KB
testcase_09 AC 1,336 ms
135,008 KB
testcase_10 AC 1,328 ms
135,008 KB
testcase_11 AC 1,291 ms
135,008 KB
testcase_12 AC 1,291 ms
135,008 KB
testcase_13 AC 1,057 ms
121,684 KB
testcase_14 AC 610 ms
101,216 KB
testcase_15 AC 575 ms
100,824 KB
testcase_16 AC 889 ms
113,864 KB
testcase_17 AC 999 ms
121,076 KB
testcase_18 AC 1,166 ms
125,808 KB
testcase_19 AC 1,056 ms
121,436 KB
testcase_20 AC 1,055 ms
121,528 KB
testcase_21 AC 1,242 ms
128,112 KB
testcase_22 AC 1,025 ms
121,120 KB
testcase_23 AC 55 ms
68,428 KB
testcase_24 AC 42 ms
62,096 KB
testcase_25 AC 44 ms
61,824 KB
testcase_26 AC 47 ms
63,908 KB
testcase_27 AC 54 ms
68,424 KB
testcase_28 AC 869 ms
118,652 KB
testcase_29 AC 314 ms
89,752 KB
testcase_30 AC 312 ms
89,908 KB
testcase_31 AC 308 ms
87,564 KB
testcase_32 AC 830 ms
114,340 KB
testcase_33 AC 34 ms
53,460 KB
testcase_34 AC 34 ms
53,460 KB
testcase_35 AC 36 ms
53,460 KB
testcase_36 AC 34 ms
53,456 KB
testcase_37 AC 36 ms
53,460 KB
testcase_38 AC 35 ms
53,460 KB
testcase_39 AC 35 ms
53,460 KB
testcase_40 AC 35 ms
53,460 KB
testcase_41 AC 34 ms
53,460 KB
testcase_42 AC 35 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
LR = []
for i in range(N):
    L, R = map(int, input().split())
    LR.append((L, R))

D = []
for i in range(N):
    D.append((LR[i][0], i+N))
    D.append((LR[i][1], i))
    
D.sort(reverse=True)
M = 20
dp = [[-1] * N for i in range(M)]
nex = -1
for _, d in D:
    if d < N:
        dp[0][d] = nex
    else:
        d -= N
        if nex == -1 or LR[d][1] <= LR[nex][1]:
            nex = d
            
for i in range(1, M):
    for j in range(N):
        if dp[i-1][j] != -1:
            dp[i][j] = dp[i-1][dp[i-1][j]]
        
inf = 10 ** 18
ans = inf
for i in range(N):
    now = i
    for j in range(M):
        if ((K - 1) >> j) & 1:
            now = dp[j][now]
            if now == -1:
                break
            
    if now != -1:
        ans = min(ans, LR[now][1] - LR[i][0])
        
print(ans) if ans != inf else print(-1)
0