結果

問題 No.2667 Constrained Permutation
ユーザー ゼットゼット
提出日時 2024-03-08 22:36:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 890 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 132,064 KB
最終ジャッジ日時 2024-03-08 22:37:02
合計ジャッジ時間 12,758 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 129 ms
77,072 KB
testcase_03 AC 140 ms
76,152 KB
testcase_04 AC 145 ms
77,388 KB
testcase_05 AC 117 ms
76,716 KB
testcase_06 AC 143 ms
77,648 KB
testcase_07 AC 44 ms
55,588 KB
testcase_08 AC 95 ms
76,588 KB
testcase_09 AC 97 ms
76,592 KB
testcase_10 AC 54 ms
59,692 KB
testcase_11 AC 88 ms
76,600 KB
testcase_12 AC 167 ms
88,056 KB
testcase_13 AC 66 ms
70,904 KB
testcase_14 AC 286 ms
114,280 KB
testcase_15 AC 394 ms
116,584 KB
testcase_16 AC 376 ms
103,676 KB
testcase_17 AC 230 ms
84,216 KB
testcase_18 AC 300 ms
114,912 KB
testcase_19 AC 302 ms
114,656 KB
testcase_20 AC 306 ms
115,432 KB
testcase_21 AC 544 ms
132,064 KB
testcase_22 AC 531 ms
132,064 KB
testcase_23 AC 556 ms
132,064 KB
testcase_24 AC 161 ms
90,688 KB
testcase_25 AC 260 ms
103,604 KB
testcase_26 AC 312 ms
115,060 KB
testcase_27 AC 340 ms
114,992 KB
testcase_28 AC 240 ms
105,600 KB
testcase_29 AC 222 ms
99,840 KB
testcase_30 AC 245 ms
103,428 KB
testcase_31 AC 176 ms
94,116 KB
testcase_32 AC 87 ms
78,072 KB
testcase_33 AC 517 ms
130,792 KB
testcase_34 AC 183 ms
94,104 KB
testcase_35 AC 318 ms
106,104 KB
testcase_36 AC 334 ms
104,316 KB
testcase_37 AC 356 ms
110,712 KB
testcase_38 AC 241 ms
105,208 KB
testcase_39 AC 68 ms
72,984 KB
testcase_40 AC 184 ms
94,104 KB
testcase_41 AC 257 ms
107,340 KB
testcase_42 AC 207 ms
94,104 KB
testcase_43 AC 241 ms
103,416 KB
testcase_44 AC 141 ms
88,056 KB
testcase_45 AC 67 ms
70,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
l=0
r=10**10
L=[]
R=[]
h=[]
u=10**10
for i in range(N):
  a,b=map(int,input().split())
  L.append(a-1)
  R.append(b-1)
  h.append([a-1,b-1])
  u=min(u,a-1)
L.sort()
R.sort()
for i in range(N):
  l=max(l,L[i]-i)
for i in range(N):
  r=min(r,R[i]-i)
if l>r:
  print(0)
  exit()
ans=r-l+1
if ans>10**2:
  print(ans)
  exit()
p=0
for i in range(N):
  h[i][0]-=u
  h[i][1]-=u
  p=max(p,h[i][0])
if p>10**7:
  print(ans)
  exit()
G=[[] for i in range(p+1)]
for i in range(N):
  x,y=h[i][:]
  G[x].append(y)
result=0
from heapq import heappush,heappop
for k in range(l-u,r-u+1):
  S=[]
  b=True
  for x in range(k):
    for y in G[x]:
      heappush(S,y)
  for i in range(N):
    t=i+k
    if t<=p:
      for y in G[t]:
        heappush(S,y)
    if len(S)==0:
      b=False
      break
    w=heappop(S)
    if w<t:
      b=False
      break
  if b==True:
    result+=1
print(result)
0