結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 46 ms
63,888 KB
testcase_03 AC 67 ms
68,152 KB
testcase_04 AC 80 ms
76,580 KB
testcase_05 AC 46 ms
63,900 KB
testcase_06 AC 80 ms
76,580 KB
testcase_07 AC 44 ms
61,312 KB
testcase_08 AC 82 ms
76,684 KB
testcase_09 AC 84 ms
76,556 KB
testcase_10 AC 49 ms
63,364 KB
testcase_11 AC 78 ms
76,696 KB
testcase_12 AC 252 ms
87,552 KB
testcase_13 AC 91 ms
76,684 KB
testcase_14 AC 604 ms
112,920 KB
testcase_15 AC 478 ms
101,656 KB
testcase_16 AC 356 ms
93,556 KB
testcase_17 AC 173 ms
81,280 KB
testcase_18 AC 634 ms
114,176 KB
testcase_19 AC 632 ms
108,812 KB
testcase_20 AC 636 ms
110,668 KB
testcase_21 AC 552 ms
107,584 KB
testcase_22 AC 596 ms
108,620 KB
testcase_23 AC 592 ms
107,776 KB
testcase_24 AC 301 ms
91,776 KB
testcase_25 AC 534 ms
110,180 KB
testcase_26 AC 633 ms
114,900 KB
testcase_27 AC 626 ms
114,416 KB
testcase_28 AC 324 ms
100,736 KB
testcase_29 AC 314 ms
97,668 KB
testcase_30 AC 355 ms
100,596 KB
testcase_31 AC 219 ms
91,116 KB
testcase_32 AC 94 ms
78,484 KB
testcase_33 AC 505 ms
94,280 KB
testcase_34 AC 304 ms
86,492 KB
testcase_35 AC 349 ms
87,988 KB
testcase_36 AC 329 ms
87,156 KB
testcase_37 AC 341 ms
89,072 KB
testcase_38 AC 481 ms
99,968 KB
testcase_39 AC 94 ms
76,812 KB
testcase_40 AC 233 ms
85,152 KB
testcase_41 AC 348 ms
91,908 KB
testcase_42 AC 341 ms
96,712 KB
testcase_43 AC 452 ms
105,484 KB
testcase_44 AC 248 ms
87,552 KB
testcase_45 AC 105 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(l - i for i, (l, _) in enumerate(lr, 1))

    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 for i, r in enumerate(sorted(r for _, r in lr), 1))
    print(max_k - min_k + 1)
0