結果

問題 No.2543 Many Meetings
ユーザー ShirotsumeShirotsume
提出日時 2023-11-14 01:51:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,539 ms / 2,000 ms
コード長 1,672 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 170,576 KB
最終ジャッジ日時 2023-11-14 01:53:26
合計ジャッジ時間 30,321 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
56,144 KB
testcase_01 AC 40 ms
56,144 KB
testcase_02 AC 41 ms
56,144 KB
testcase_03 AC 1,379 ms
170,192 KB
testcase_04 AC 1,393 ms
170,088 KB
testcase_05 AC 1,389 ms
170,092 KB
testcase_06 AC 1,396 ms
170,192 KB
testcase_07 AC 1,429 ms
170,104 KB
testcase_08 AC 1,534 ms
170,100 KB
testcase_09 AC 1,539 ms
170,496 KB
testcase_10 AC 1,530 ms
170,500 KB
testcase_11 AC 1,522 ms
170,100 KB
testcase_12 AC 1,534 ms
170,576 KB
testcase_13 AC 1,070 ms
150,724 KB
testcase_14 AC 598 ms
117,676 KB
testcase_15 AC 575 ms
112,500 KB
testcase_16 AC 886 ms
136,560 KB
testcase_17 AC 1,010 ms
147,976 KB
testcase_18 AC 1,052 ms
150,800 KB
testcase_19 AC 973 ms
142,500 KB
testcase_20 AC 959 ms
141,400 KB
testcase_21 AC 1,136 ms
147,444 KB
testcase_22 AC 922 ms
147,976 KB
testcase_23 AC 66 ms
73,392 KB
testcase_24 AC 48 ms
64,560 KB
testcase_25 AC 53 ms
66,772 KB
testcase_26 AC 56 ms
68,836 KB
testcase_27 AC 65 ms
73,240 KB
testcase_28 AC 1,104 ms
144,372 KB
testcase_29 AC 395 ms
98,928 KB
testcase_30 AC 414 ms
99,192 KB
testcase_31 AC 340 ms
95,668 KB
testcase_32 AC 1,026 ms
141,088 KB
testcase_33 AC 41 ms
56,144 KB
testcase_34 AC 40 ms
56,144 KB
testcase_35 AC 41 ms
56,144 KB
testcase_36 AC 41 ms
56,144 KB
testcase_37 AC 41 ms
56,144 KB
testcase_38 AC 41 ms
56,144 KB
testcase_39 AC 41 ms
56,144 KB
testcase_40 AC 41 ms
56,144 KB
testcase_41 AC 41 ms
56,144 KB
testcase_42 AC 41 ms
56,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n, k, LR):
    inf = 2 ** 63 - 1
    LR.sort()
    next = [[0] * n for _ in range(21)]
    
    d = []
    
    for i in range(n):
        d.append((LR[i][1], i))
        d.append((LR[i][0], i + n))
    d.sort(reverse=True)
    toind = -1
    
    for _, ind in d:
        if ind < n:
            next[0][ind] = toind
        else:
            ind -= n
            if toind < 0 or LR[toind][1] > LR[ind][1]:
                toind = ind
    for i in range(20):
        for j in range(n):
            if next[i][j] == -1:
                next[i + 1][j] = -1
            else:
                next[i + 1][j] = next[i][next[i][j]]
    ans = inf
    for i in range(n):
        now = i
        nowk = k - 1
        for j in range(20):
            if nowk % 2:
                now = next[j][now]
            nowk //= 2
        if now >= 0:
            x = LR[i][0]
            y = LR[now][1]
            ans = min(ans, y - x)
    return ans if ans < inf else -1

def solve_gu(n, k, LR):
    import itertools
    ans = inf
    for v in itertools.combinations(LR, k):
        v = list(v)
        v.sort(key = lambda x: x[1])
        
        now = -1
        f = True
        for l, r in v:
            if l < now:
                f = False
            now = r
        if f:
            ans = min(ans, v[-1][-1] - v[0][0])
    return ans if ans < inf else -1
import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

n, k = mi()
LR = [li() for _ in range(n)]

print(solve(n, k, LR))
0