結果
問題 | No.2304 Distinct Elements |
ユーザー | Shirotsume |
提出日時 | 2023-04-23 02:12:22 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,964 bytes |
コンパイル時間 | 657 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 133,776 KB |
最終ジャッジ日時 | 2024-04-26 21:27:19 |
合計ジャッジ時間 | 16,558 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
54,528 KB |
testcase_01 | AC | 46 ms
54,400 KB |
testcase_02 | AC | 47 ms
54,400 KB |
testcase_03 | AC | 46 ms
54,272 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 251 ms
132,244 KB |
testcase_10 | AC | 259 ms
128,404 KB |
testcase_11 | AC | 251 ms
133,660 KB |
testcase_12 | AC | 252 ms
133,776 KB |
testcase_13 | AC | 252 ms
133,528 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 50 ms
55,680 KB |
testcase_18 | AC | 52 ms
56,064 KB |
testcase_19 | AC | 46 ms
54,656 KB |
testcase_20 | AC | 45 ms
54,656 KB |
testcase_21 | AC | 46 ms
54,656 KB |
testcase_22 | AC | 46 ms
54,400 KB |
testcase_23 | AC | 47 ms
54,656 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 351 ms
101,632 KB |
testcase_30 | AC | 159 ms
78,252 KB |
testcase_31 | AC | 288 ms
96,256 KB |
testcase_32 | AC | 233 ms
118,180 KB |
testcase_33 | AC | 93 ms
79,488 KB |
testcase_34 | AC | 238 ms
124,748 KB |
testcase_35 | AC | 248 ms
125,840 KB |
testcase_36 | AC | 93 ms
79,360 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 367 ms
110,700 KB |
testcase_44 | AC | 225 ms
116,040 KB |
testcase_45 | AC | 279 ms
100,244 KB |
testcase_46 | AC | 227 ms
95,804 KB |
testcase_47 | AC | 71 ms
66,560 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | AC | 361 ms
105,908 KB |
testcase_51 | AC | 363 ms
106,040 KB |
testcase_52 | WA | - |
testcase_53 | AC | 325 ms
107,776 KB |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | AC | 465 ms
108,596 KB |
testcase_58 | AC | 444 ms
108,344 KB |
testcase_59 | WA | - |
testcase_60 | AC | 46 ms
54,528 KB |
testcase_61 | AC | 46 ms
54,400 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)