結果

問題 No.2667 Constrained Permutation
ユーザー suisensuisen
提出日時 2023-10-29 22:02:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,636 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 116,628 KB
最終ジャッジ日時 2024-01-15 12:25:39
合計ジャッジ時間 31,085 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 62 ms
66,084 KB
testcase_03 AC 102 ms
74,284 KB
testcase_04 AC 118 ms
77,340 KB
testcase_05 AC 57 ms
66,116 KB
testcase_06 AC 113 ms
76,820 KB
testcase_07 AC 48 ms
61,312 KB
testcase_08 AC 116 ms
76,940 KB
testcase_09 AC 116 ms
77,196 KB
testcase_10 AC 69 ms
70,644 KB
testcase_11 AC 105 ms
76,568 KB
testcase_12 AC 572 ms
88,576 KB
testcase_13 AC 133 ms
77,572 KB
testcase_14 AC 1,535 ms
111,468 KB
testcase_15 AC 943 ms
97,296 KB
testcase_16 AC 725 ms
92,008 KB
testcase_17 AC 326 ms
82,424 KB
testcase_18 AC 1,636 ms
114,568 KB
testcase_19 AC 1,521 ms
102,540 KB
testcase_20 AC 1,612 ms
107,416 KB
testcase_21 AC 1,224 ms
103,324 KB
testcase_22 AC 1,211 ms
103,468 KB
testcase_23 AC 1,241 ms
103,800 KB
testcase_24 AC 679 ms
92,640 KB
testcase_25 AC 1,287 ms
107,820 KB
testcase_26 AC 1,604 ms
114,688 KB
testcase_27 AC 1,623 ms
116,628 KB
testcase_28 AC 583 ms
100,736 KB
testcase_29 AC 546 ms
98,116 KB
testcase_30 AC 631 ms
100,812 KB
testcase_31 AC 380 ms
91,116 KB
testcase_32 AC 127 ms
77,332 KB
testcase_33 AC 853 ms
94,536 KB
testcase_34 AC 470 ms
86,108 KB
testcase_35 AC 547 ms
87,736 KB
testcase_36 AC 546 ms
87,796 KB
testcase_37 AC 555 ms
89,200 KB
testcase_38 AC 986 ms
96,296 KB
testcase_39 AC 137 ms
77,712 KB
testcase_40 AC 389 ms
85,152 KB
testcase_41 AC 632 ms
91,908 KB
testcase_42 AC 752 ms
97,384 KB
testcase_43 AC 1,045 ms
104,968 KB
testcase_44 AC 504 ms
89,856 KB
testcase_45 AC 128 ms
77,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

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

def get_min_k():
    lr.sort()
    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:
    lr = [(M - r, M - l) for l, r in lr]
    max_k = get_min_k()
    assert max_k is not None
    max_k = M - max_k - (n + 1)
    print(max_k - min_k + 1)
0