結果

問題 No.2667 Constrained Permutation
ユーザー suisensuisen
提出日時 2023-10-29 22:08:02
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 727 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 258,300 KB
最終ジャッジ日時 2024-01-15 12:25:48
合計ジャッジ時間 11,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
53,460 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 78 ms
75,804 KB
testcase_03 AC 97 ms
75,936 KB
testcase_04 AC 131 ms
77,472 KB
testcase_05 AC 69 ms
72,484 KB
testcase_06 AC 133 ms
77,476 KB
testcase_07 AC 46 ms
62,080 KB
testcase_08 AC 84 ms
76,684 KB
testcase_09 AC 85 ms
76,556 KB
testcase_10 AC 55 ms
68,288 KB
testcase_11 AC 81 ms
76,688 KB
testcase_12 AC 758 ms
105,692 KB
testcase_13 AC 145 ms
77,324 KB
testcase_14 TLE -
testcase_15 AC 596 ms
197,656 KB
testcase_16 AC 453 ms
171,004 KB
testcase_17 AC 200 ms
100,348 KB
testcase_18 TLE -
testcase_19 AC 1,451 ms
136,716 KB
testcase_20 AC 1,648 ms
133,036 KB
testcase_21 AC 732 ms
215,920 KB
testcase_22 AC 869 ms
256,888 KB
testcase_23 AC 831 ms
258,300 KB
testcase_24 AC 1,040 ms
131,476 KB
testcase_25 TLE -
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

n = int(input())
lr = [tuple(map(int, input().split())) for _ in range(n)]

def check(k: int):
    pq = []
    j = 0
    for v in range(k + 1, k + n + 1):
        while j < n and lr[j][0] <= v:
            heapq.heappush(pq, lr[j][1])
            j += 1
        if pq[0] < v:
            return False
        heapq.heappop(pq)
    return True


def get_min_k():
    lr.sort(key=lambda t: t[0])
    k = max(lr[i][0] - (i + 1) for i in range(n))
    return k if check(k) else None

min_k = get_min_k()
if min_k is None:
    print(0)
else:
    ok, ng = min_k, 10 ** 9
    while ng - ok > 1:
        k = (ok + ng) >> 1
        if check(k):
            ok = k
        else:
            ng = k
    print(ok - min_k + 1)
0