結果
問題 | No.2304 Distinct Elements |
ユーザー | Shirotsume |
提出日時 | 2023-04-23 02:12:22 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,964 bytes |
コンパイル時間 | 403 ms |
コンパイル使用メモリ | 82,392 KB |
実行使用メモリ | 133,996 KB |
最終ジャッジ日時 | 2024-11-14 12:48:29 |
合計ジャッジ時間 | 15,670 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
55,452 KB |
testcase_01 | AC | 41 ms
55,348 KB |
testcase_02 | AC | 42 ms
55,328 KB |
testcase_03 | AC | 42 ms
55,680 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 241 ms
132,192 KB |
testcase_10 | AC | 246 ms
128,592 KB |
testcase_11 | AC | 239 ms
133,996 KB |
testcase_12 | AC | 244 ms
133,616 KB |
testcase_13 | AC | 248 ms
133,868 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 46 ms
56,320 KB |
testcase_18 | AC | 48 ms
57,696 KB |
testcase_19 | AC | 42 ms
54,868 KB |
testcase_20 | AC | 41 ms
55,140 KB |
testcase_21 | AC | 44 ms
56,508 KB |
testcase_22 | AC | 43 ms
56,024 KB |
testcase_23 | AC | 42 ms
54,988 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 295 ms
101,884 KB |
testcase_30 | AC | 151 ms
78,472 KB |
testcase_31 | AC | 265 ms
96,312 KB |
testcase_32 | AC | 229 ms
118,132 KB |
testcase_33 | AC | 81 ms
79,744 KB |
testcase_34 | AC | 225 ms
124,692 KB |
testcase_35 | AC | 238 ms
126,044 KB |
testcase_36 | AC | 81 ms
79,448 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 351 ms
110,704 KB |
testcase_44 | AC | 221 ms
116,224 KB |
testcase_45 | AC | 267 ms
100,172 KB |
testcase_46 | AC | 216 ms
96,020 KB |
testcase_47 | AC | 64 ms
66,464 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | AC | 369 ms
105,996 KB |
testcase_51 | AC | 358 ms
105,492 KB |
testcase_52 | WA | - |
testcase_53 | AC | 305 ms
107,724 KB |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | AC | 455 ms
108,660 KB |
testcase_58 | AC | 433 ms
108,568 KB |
testcase_59 | WA | - |
testcase_60 | AC | 42 ms
55,652 KB |
testcase_61 | AC | 44 ms
54,768 KB |
ソースコード
import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 import heapq class MedianHeap(): def __init__(self): self.top = [] self.bottom = [] def __len__(self): return len(self.top) + len(self.bottom) def add(self, x): heapq.heappush(self.top, x) while len(self.top) - 2 >= len(self.bottom): heapq.heappush(self.bottom, -heapq.heappop(self.top)) while self.top and self.bottom and self.top[0] < -self.bottom[0]: x = heapq.heappop(self.top) y = heapq.heappop(self.bottom) heapq.heappush(self.top, -y) heapq.heappush(self.bottom, -x) def med(self): if len(self) % 2: return self.top[0], self.top[0] else: return -self.bottom[0], self.top[0] n = ii() a = li() a.sort() a = [a[i] - i for i in range(n)] stack = [] for V in a: M = MedianHeap() M.add(V) stack.append(M) while len(stack) >= 2: X = stack.pop() Y = stack.pop() m2, M2 = X.med() m1, M1 = Y.med() if m1 < M2: stack.append(Y) stack.append(X) break else: if len(X) < len(Y): for v in X.top: Y.add(v) for v in X.bottom: Y.add(-v) stack.append(Y) else: for v in Y.top: X.add(v) for v in Y.bottom: X.add(-v) stack.append(X) P = [len(stack[i]) for i in range(len(stack))] cnt = 0 b = [0] * n for i, v in enumerate(P): med = max(b[cnt - 1], stack[i].med()[0]) for x in range(v): b[cnt] = med cnt += 1 ans = sum([abs(a[i] - b[i]) for i in range(n)]) print(ans)