結果

問題 No.2667 Constrained Permutation
ユーザー suisensuisen
提出日時 2023-10-29 22:05:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 967 ms / 2,000 ms
コード長 663 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 116,508 KB
最終ジャッジ日時 2024-01-15 12:25:30
合計ジャッジ時間 19,682 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,460 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 55 ms
66,084 KB
testcase_03 AC 77 ms
75,812 KB
testcase_04 AC 106 ms
77,340 KB
testcase_05 AC 50 ms
66,104 KB
testcase_06 AC 100 ms
77,344 KB
testcase_07 AC 40 ms
61,312 KB
testcase_08 AC 103 ms
77,448 KB
testcase_09 AC 108 ms
77,320 KB
testcase_10 AC 61 ms
70,640 KB
testcase_11 AC 95 ms
76,692 KB
testcase_12 AC 353 ms
88,316 KB
testcase_13 AC 108 ms
77,320 KB
testcase_14 AC 878 ms
116,508 KB
testcase_15 AC 583 ms
97,312 KB
testcase_16 AC 491 ms
92,284 KB
testcase_17 AC 255 ms
82,172 KB
testcase_18 AC 939 ms
112,788 KB
testcase_19 AC 910 ms
112,420 KB
testcase_20 AC 967 ms
116,044 KB
testcase_21 AC 736 ms
112,104 KB
testcase_22 AC 736 ms
102,640 KB
testcase_23 AC 757 ms
102,908 KB
testcase_24 AC 433 ms
96,888 KB
testcase_25 AC 738 ms
110,168 KB
testcase_26 AC 860 ms
113,872 KB
testcase_27 AC 882 ms
114,788 KB
testcase_28 AC 324 ms
100,860 KB
testcase_29 AC 311 ms
97,652 KB
testcase_30 AC 341 ms
100,588 KB
testcase_31 AC 227 ms
91,240 KB
testcase_32 AC 92 ms
78,480 KB
testcase_33 AC 507 ms
94,276 KB
testcase_34 AC 293 ms
86,492 KB
testcase_35 AC 348 ms
87,980 KB
testcase_36 AC 322 ms
87,152 KB
testcase_37 AC 335 ms
89,068 KB
testcase_38 AC 620 ms
95,872 KB
testcase_39 AC 125 ms
77,704 KB
testcase_40 AC 239 ms
85,148 KB
testcase_41 AC 357 ms
91,904 KB
testcase_42 AC 479 ms
97,096 KB
testcase_43 AC 674 ms
108,296 KB
testcase_44 AC 326 ms
88,316 KB
testcase_45 AC 111 ms
77,404 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:
    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