結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 52 ms
63,888 KB
testcase_03 AC 64 ms
68,152 KB
testcase_04 AC 90 ms
76,704 KB
testcase_05 AC 51 ms
63,900 KB
testcase_06 AC 91 ms
76,580 KB
testcase_07 AC 47 ms
61,312 KB
testcase_08 AC 90 ms
76,684 KB
testcase_09 AC 93 ms
76,560 KB
testcase_10 AC 54 ms
63,364 KB
testcase_11 AC 85 ms
76,692 KB
testcase_12 AC 296 ms
87,936 KB
testcase_13 AC 101 ms
76,684 KB
testcase_14 AC 688 ms
114,204 KB
testcase_15 AC 545 ms
102,936 KB
testcase_16 AC 403 ms
94,340 KB
testcase_17 AC 188 ms
81,536 KB
testcase_18 AC 711 ms
115,700 KB
testcase_19 AC 717 ms
110,248 KB
testcase_20 AC 722 ms
112,464 KB
testcase_21 AC 631 ms
109,116 KB
testcase_22 AC 685 ms
109,436 KB
testcase_23 AC 684 ms
109,648 KB
testcase_24 AC 338 ms
92,500 KB
testcase_25 AC 646 ms
111,196 KB
testcase_26 AC 746 ms
116,444 KB
testcase_27 AC 747 ms
115,948 KB
testcase_28 AC 395 ms
100,736 KB
testcase_29 AC 381 ms
97,660 KB
testcase_30 AC 424 ms
100,592 KB
testcase_31 AC 263 ms
91,244 KB
testcase_32 AC 111 ms
78,484 KB
testcase_33 AC 599 ms
94,280 KB
testcase_34 AC 350 ms
86,496 KB
testcase_35 AC 405 ms
87,988 KB
testcase_36 AC 383 ms
87,156 KB
testcase_37 AC 390 ms
89,072 KB
testcase_38 AC 550 ms
101,116 KB
testcase_39 AC 108 ms
76,812 KB
testcase_40 AC 270 ms
85,152 KB
testcase_41 AC 440 ms
91,908 KB
testcase_42 AC 383 ms
96,832 KB
testcase_43 AC 513 ms
106,896 KB
testcase_44 AC 300 ms
87,808 KB
testcase_45 AC 103 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

M = 10 ** 9 + 1

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