結果
問題 | No.738 平らな農地 |
ユーザー | rlangevin |
提出日時 | 2024-02-07 12:23:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 377 ms / 2,000 ms |
コード長 | 1,809 bytes |
コンパイル時間 | 444 ms |
コンパイル使用メモリ | 82,120 KB |
実行使用メモリ | 101,104 KB |
最終ジャッジ日時 | 2024-09-28 12:28:46 |
合計ジャッジ時間 | 22,390 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
55,240 KB |
testcase_01 | AC | 42 ms
55,352 KB |
testcase_02 | AC | 41 ms
54,672 KB |
testcase_03 | AC | 42 ms
54,268 KB |
testcase_04 | AC | 43 ms
55,288 KB |
testcase_05 | AC | 115 ms
77,956 KB |
testcase_06 | AC | 109 ms
77,836 KB |
testcase_07 | AC | 114 ms
79,420 KB |
testcase_08 | AC | 87 ms
76,868 KB |
testcase_09 | AC | 68 ms
73,084 KB |
testcase_10 | AC | 56 ms
65,548 KB |
testcase_11 | AC | 85 ms
76,820 KB |
testcase_12 | AC | 68 ms
72,548 KB |
testcase_13 | AC | 108 ms
77,620 KB |
testcase_14 | AC | 78 ms
75,752 KB |
testcase_15 | AC | 297 ms
91,812 KB |
testcase_16 | AC | 301 ms
93,784 KB |
testcase_17 | AC | 326 ms
93,324 KB |
testcase_18 | AC | 312 ms
92,180 KB |
testcase_19 | AC | 338 ms
94,616 KB |
testcase_20 | AC | 301 ms
93,760 KB |
testcase_21 | AC | 339 ms
93,484 KB |
testcase_22 | AC | 302 ms
93,780 KB |
testcase_23 | AC | 337 ms
93,924 KB |
testcase_24 | AC | 347 ms
94,044 KB |
testcase_25 | AC | 70 ms
74,392 KB |
testcase_26 | AC | 76 ms
76,072 KB |
testcase_27 | AC | 77 ms
76,176 KB |
testcase_28 | AC | 70 ms
73,896 KB |
testcase_29 | AC | 78 ms
75,860 KB |
testcase_30 | AC | 78 ms
75,904 KB |
testcase_31 | AC | 70 ms
73,516 KB |
testcase_32 | AC | 68 ms
73,192 KB |
testcase_33 | AC | 77 ms
75,812 KB |
testcase_34 | AC | 70 ms
73,268 KB |
testcase_35 | AC | 67 ms
73,096 KB |
testcase_36 | AC | 69 ms
72,968 KB |
testcase_37 | AC | 70 ms
74,064 KB |
testcase_38 | AC | 75 ms
75,616 KB |
testcase_39 | AC | 80 ms
75,640 KB |
testcase_40 | AC | 80 ms
75,892 KB |
testcase_41 | AC | 78 ms
76,140 KB |
testcase_42 | AC | 73 ms
74,124 KB |
testcase_43 | AC | 67 ms
72,956 KB |
testcase_44 | AC | 70 ms
73,716 KB |
testcase_45 | AC | 306 ms
94,968 KB |
testcase_46 | AC | 304 ms
93,020 KB |
testcase_47 | AC | 311 ms
95,904 KB |
testcase_48 | AC | 289 ms
95,564 KB |
testcase_49 | AC | 286 ms
93,624 KB |
testcase_50 | AC | 294 ms
95,364 KB |
testcase_51 | AC | 309 ms
95,000 KB |
testcase_52 | AC | 298 ms
94,268 KB |
testcase_53 | AC | 308 ms
95,728 KB |
testcase_54 | AC | 318 ms
94,892 KB |
testcase_55 | AC | 319 ms
94,996 KB |
testcase_56 | AC | 317 ms
95,584 KB |
testcase_57 | AC | 298 ms
93,272 KB |
testcase_58 | AC | 303 ms
94,708 KB |
testcase_59 | AC | 307 ms
95,340 KB |
testcase_60 | AC | 306 ms
94,932 KB |
testcase_61 | AC | 301 ms
95,684 KB |
testcase_62 | AC | 313 ms
92,648 KB |
testcase_63 | AC | 308 ms
94,960 KB |
testcase_64 | AC | 307 ms
95,156 KB |
testcase_65 | AC | 344 ms
96,840 KB |
testcase_66 | AC | 330 ms
94,204 KB |
testcase_67 | AC | 264 ms
98,132 KB |
testcase_68 | AC | 266 ms
100,776 KB |
testcase_69 | AC | 340 ms
100,460 KB |
testcase_70 | AC | 316 ms
100,420 KB |
testcase_71 | AC | 262 ms
91,932 KB |
testcase_72 | AC | 249 ms
91,000 KB |
testcase_73 | AC | 232 ms
92,332 KB |
testcase_74 | AC | 261 ms
92,504 KB |
testcase_75 | AC | 304 ms
98,324 KB |
testcase_76 | AC | 308 ms
101,104 KB |
testcase_77 | AC | 334 ms
97,284 KB |
testcase_78 | AC | 334 ms
100,276 KB |
testcase_79 | AC | 326 ms
100,340 KB |
testcase_80 | AC | 288 ms
100,236 KB |
testcase_81 | AC | 310 ms
99,972 KB |
testcase_82 | AC | 334 ms
100,032 KB |
testcase_83 | AC | 286 ms
92,176 KB |
testcase_84 | AC | 249 ms
92,516 KB |
testcase_85 | AC | 377 ms
100,028 KB |
testcase_86 | AC | 350 ms
97,684 KB |
testcase_87 | AC | 224 ms
99,720 KB |
testcase_88 | AC | 211 ms
97,120 KB |
testcase_89 | AC | 43 ms
54,976 KB |
testcase_90 | AC | 42 ms
55,456 KB |
testcase_91 | AC | 42 ms
54,796 KB |
ソースコード
class Fenwick_Tree: def __init__(self, n): self._n = n self.data = [0] * n def add(self, p, x): assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p - 1] += x p += p & -p def sum(self, l, r): assert 0 <= l <= r <= self._n return self._sum(r) - self._sum(l) def _sum(self, r): s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s def get(self, k): k += 1 x, r = 0, 1 while r < self._n: r <<= 1 len = r while len: if x + len - 1 < self._n: if self.data[x + len - 1] < k: k -= self.data[x + len - 1] x += len len >>= 1 return x from bisect import * from copy import * def compress(lst): B = [] D = dict() vals = deepcopy(lst) vals = list(set(vals)) vals.sort() for i in range(len(lst)): ind = bisect_left(vals, lst[i]) B.append(ind) for i in range(len(B)): D[lst[i]] = B[i] return B, D, vals N, K = map(int, input().split()) A = list(map(int, input().split())) + [-1] A, _, itov = compress(A) Ts = Fenwick_Tree(N + 5) Tn = Fenwick_Tree(N + 5) for i in range(K): Ts.add(A[i], itov[A[i]]) Tn.add(A[i], 1) ind = Tn.get(K//2) ans = Ts.sum(ind + 1, N + 5) - Ts.sum(0, ind) + itov[ind] * (Tn.sum(0, ind) - Tn.sum(ind+1, N + 5)) for i in range(K, N): Ts.add(A[i-K], -itov[A[i-K]]) Ts.add(A[i], itov[A[i]]) Tn.add(A[i-K], -1) Tn.add(A[i], 1) ind = Tn.get(K//2) val = itov[ind] ans = min(ans, Ts.sum(ind + 1, N + 5) - Ts.sum(0, ind) + val * (Tn.sum(0, ind) - Tn.sum(ind+1, N + 5))) print(ans)