結果

問題 No.2667 Constrained Permutation
ユーザー ShirotsumeShirotsume
提出日時 2023-12-30 01:29:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,178 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 148,780 KB
最終ジャッジ日時 2024-01-15 12:26:37
合計ジャッジ時間 32,951 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
56,140 KB
testcase_01 AC 42 ms
56,140 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 799 ms
104,304 KB
testcase_29 AC 745 ms
103,100 KB
testcase_30 AC 853 ms
117,848 KB
testcase_31 AC 514 ms
93,628 KB
testcase_32 AC 140 ms
80,352 KB
testcase_33 AC 1,491 ms
147,328 KB
testcase_34 AC 782 ms
113,332 KB
testcase_35 AC 920 ms
117,760 KB
testcase_36 AC 865 ms
115,124 KB
testcase_37 AC 995 ms
121,520 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 826 ms
112,684 KB
testcase_41 AC 1,307 ms
137,160 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 61 - 1
mod = 998244353
import heapq
n = ii()

LR = []
lr = []
for i in range(n):
    l, r = mi()
    lr.append((l, r))
    LR.append((l, -1))
    LR.append((r, 1))
LR.sort()

LR2 = [[0, 0] for _ in range(n)]
lcnt = 0
rcnt = 0
for v, x in LR:
    if x == -1:
        LR2[lcnt][0] = v
        lcnt += 1
    else:
        LR2[rcnt][1] = v
        rcnt += 1
    
mink = -inf
maxk = inf
LR2 = LR2[::]
for i in range(n):
    l, r = LR2[i]
    mink = max(mink, l - i)
    maxk = min(maxk, r - i)
ans = max(0, maxk - mink + 1)
now = mink
cnt = 0
q = []
nex = []
for l, r in lr:
    if l < now <= r:
        heapq.heappush(q, r)
    elif r >= now:
        nex.append((l, r))
    else:
        ans = 0
        break
        
nex.sort()


for l, r in nex:
    if l > now:
        ans = 0
        break
    heapq.heappush(q, r)
    to = heapq.heappop(q)
    if to < now:
        ans = 0
        break
    now += 1
    
print(ans)
        

        
        
    
    
0