結果
問題 | No.2667 Constrained Permutation |
ユーザー | Shirotsume |
提出日時 | 2023-12-30 01:41:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,638 ms / 2,000 ms |
コード長 | 1,172 bytes |
コンパイル時間 | 494 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 151,232 KB |
最終ジャッジ日時 | 2024-09-28 02:20:09 |
合計ジャッジ時間 | 37,178 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
55,936 KB |
testcase_01 | AC | 51 ms
55,552 KB |
testcase_02 | AC | 66 ms
64,768 KB |
testcase_03 | AC | 79 ms
70,144 KB |
testcase_04 | AC | 108 ms
77,696 KB |
testcase_05 | AC | 63 ms
64,128 KB |
testcase_06 | AC | 107 ms
77,696 KB |
testcase_07 | AC | 58 ms
58,240 KB |
testcase_08 | AC | 109 ms
78,336 KB |
testcase_09 | AC | 111 ms
77,824 KB |
testcase_10 | AC | 70 ms
67,328 KB |
testcase_11 | AC | 101 ms
77,696 KB |
testcase_12 | AC | 586 ms
100,216 KB |
testcase_13 | AC | 122 ms
78,464 KB |
testcase_14 | AC | 1,504 ms
147,676 KB |
testcase_15 | AC | 1,219 ms
131,820 KB |
testcase_16 | AC | 849 ms
114,640 KB |
testcase_17 | AC | 331 ms
88,856 KB |
testcase_18 | AC | 1,622 ms
151,232 KB |
testcase_19 | AC | 1,596 ms
147,396 KB |
testcase_20 | AC | 1,638 ms
148,924 KB |
testcase_21 | AC | 1,526 ms
147,912 KB |
testcase_22 | AC | 1,534 ms
147,912 KB |
testcase_23 | AC | 1,530 ms
148,280 KB |
testcase_24 | AC | 674 ms
106,124 KB |
testcase_25 | AC | 1,285 ms
136,272 KB |
testcase_26 | AC | 1,559 ms
150,880 KB |
testcase_27 | AC | 1,567 ms
150,948 KB |
testcase_28 | AC | 1,031 ms
132,368 KB |
testcase_29 | AC | 987 ms
131,160 KB |
testcase_30 | AC | 1,118 ms
134,776 KB |
testcase_31 | AC | 682 ms
113,508 KB |
testcase_32 | AC | 196 ms
83,584 KB |
testcase_33 | AC | 1,440 ms
145,956 KB |
testcase_34 | AC | 811 ms
113,612 KB |
testcase_35 | AC | 921 ms
118,176 KB |
testcase_36 | AC | 899 ms
115,648 KB |
testcase_37 | AC | 989 ms
121,548 KB |
testcase_38 | AC | 1,133 ms
126,920 KB |
testcase_39 | AC | 128 ms
78,464 KB |
testcase_40 | AC | 690 ms
97,732 KB |
testcase_41 | AC | 1,114 ms
114,904 KB |
testcase_42 | AC | 764 ms
114,632 KB |
testcase_43 | AC | 1,058 ms
131,248 KB |
testcase_44 | AC | 526 ms
101,240 KB |
testcase_45 | AC | 121 ms
78,720 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 = [] graph =[[] for _ in range(n)] for l, r in lr: if l < now: graph[0].append(r) elif now <= l <= now + n - 1: graph[l - now].append(r) else: ans = 0 break for i in range(n): for v in graph[i]: heapq.heappush(q, v) to = heapq.heappop(q) if to < now: ans = 0 break now += 1 print(ans)