結果
問題 | No.2543 Many Meetings |
ユーザー |
|
提出日時 | 2023-11-24 22:35:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 851 ms / 2,000 ms |
コード長 | 911 bytes |
コンパイル時間 | 449 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 161,140 KB |
最終ジャッジ日時 | 2024-09-26 09:38:46 |
合計ジャッジ時間 | 19,505 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
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)