結果

問題 No.2667 Constrained Permutation
ユーザー suisensuisen
提出日時 2023-11-18 03:43:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 746 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 114,920 KB
最終ジャッジ日時 2024-01-15 12:26:00
合計ジャッジ時間 18,118 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 53 ms
63,888 KB
testcase_03 AC 64 ms
68,152 KB
testcase_04 AC 90 ms
76,704 KB
testcase_05 AC 50 ms
61,824 KB
testcase_06 AC 92 ms
76,580 KB
testcase_07 AC 47 ms
61,312 KB
testcase_08 AC 91 ms
76,684 KB
testcase_09 AC 94 ms
76,560 KB
testcase_10 AC 56 ms
63,364 KB
testcase_11 AC 86 ms
76,692 KB
testcase_12 AC 301 ms
87,552 KB
testcase_13 AC 101 ms
76,684 KB
testcase_14 AC 716 ms
112,672 KB
testcase_15 AC 554 ms
101,660 KB
testcase_16 AC 418 ms
93,516 KB
testcase_17 AC 198 ms
81,280 KB
testcase_18 AC 746 ms
114,300 KB
testcase_19 AC 724 ms
108,832 KB
testcase_20 AC 737 ms
110,672 KB
testcase_21 AC 639 ms
107,576 KB
testcase_22 AC 686 ms
107,896 KB
testcase_23 AC 696 ms
108,028 KB
testcase_24 AC 347 ms
91,776 KB
testcase_25 AC 627 ms
110,156 KB
testcase_26 AC 724 ms
114,920 KB
testcase_27 AC 735 ms
114,416 KB
testcase_28 AC 380 ms
100,736 KB
testcase_29 AC 366 ms
97,664 KB
testcase_30 AC 418 ms
100,596 KB
testcase_31 AC 258 ms
91,244 KB
testcase_32 AC 107 ms
78,484 KB
testcase_33 AC 585 ms
94,280 KB
testcase_34 AC 339 ms
86,496 KB
testcase_35 AC 399 ms
87,984 KB
testcase_36 AC 368 ms
87,156 KB
testcase_37 AC 379 ms
89,072 KB
testcase_38 AC 534 ms
99,960 KB
testcase_39 AC 108 ms
76,812 KB
testcase_40 AC 257 ms
85,152 KB
testcase_41 AC 390 ms
91,908 KB
testcase_42 AC 373 ms
96,960 KB
testcase_43 AC 497 ms
105,484 KB
testcase_44 AC 282 ms
87,552 KB
testcase_45 AC 101 ms
76,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

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

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

    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 None
        heapq.heappop(pq)
    return k

min_k = get_min_k()
if min_k is None:
    print(0)
else:
    max_k = min(r - (i + 1) for i, r in enumerate(sorted(r for _, r in lr)))
    print(max_k - min_k + 1)
0