結果
問題 | No.2667 Constrained Permutation |
ユーザー | Shirotsume |
提出日時 | 2023-12-30 01:32:08 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,258 bytes |
コンパイル時間 | 214 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 148,900 KB |
最終ジャッジ日時 | 2024-01-15 12:27:09 |
合計ジャッジ時間 | 38,239 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
56,140 KB |
testcase_01 | AC | 43 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 | AC | 557 ms
96,352 KB |
testcase_13 | AC | 108 ms
78,176 KB |
testcase_14 | AC | 1,405 ms
134,984 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 1,482 ms
138,144 KB |
testcase_19 | WA | - |
testcase_20 | AC | 1,728 ms
143,140 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 604 ms
102,128 KB |
testcase_25 | AC | 1,152 ms
125,872 KB |
testcase_26 | AC | 1,392 ms
137,668 KB |
testcase_27 | AC | 1,407 ms
138,372 KB |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | AC | 1,639 ms
147,456 KB |
testcase_34 | AC | 889 ms
113,448 KB |
testcase_35 | AC | 1,024 ms
117,888 KB |
testcase_36 | AC | 980 ms
115,248 KB |
testcase_37 | AC | 1,115 ms
121,648 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 874 ms
112,936 KB |
testcase_41 | AC | 1,438 ms
137,288 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 498 ms
96,608 KB |
testcase_45 | AC | 104 ms
78,304 KB |
ソースコード
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(reverse=True) for _ in range(n): if nex: l, r = nex[-1] if l > now: pass else: nex.pop() heapq.heappush(q, r) to = heapq.heappop(q) if to < now: ans = 0 break now += 1 print(ans)