結果
問題 | No.2304 Distinct Elements |
ユーザー | Shirotsume |
提出日時 | 2023-04-23 02:46:34 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,893 bytes |
コンパイル時間 | 345 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 141,264 KB |
最終ジャッジ日時 | 2024-04-26 21:28:53 |
合計ジャッジ時間 | 5,543 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
60,032 KB |
testcase_01 | AC | 45 ms
54,016 KB |
testcase_02 | AC | 44 ms
54,016 KB |
testcase_03 | AC | 45 ms
54,272 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
ソースコード
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] else: return 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 = X.med() m1 = Y.med() if m1 <= m2: stack.append(Y) stack.append(X) break else: if 0: 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 = stack[i].med() for x in range(v): b[cnt] = med cnt += 1 ans = sum([abs(a[i] - b[i]) for i in range(n)]) print(ans)