結果
問題 | No.2139 K Consecutive Sushi |
ユーザー | shotoyoo |
提出日時 | 2022-12-03 00:10:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 280 ms / 2,000 ms |
コード長 | 4,512 bytes |
コンパイル時間 | 223 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 121,096 KB |
最終ジャッジ日時 | 2024-05-05 19:21:26 |
合計ジャッジ時間 | 6,687 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
54,912 KB |
testcase_01 | AC | 46 ms
54,528 KB |
testcase_02 | AC | 44 ms
54,784 KB |
testcase_03 | AC | 275 ms
120,968 KB |
testcase_04 | AC | 280 ms
121,096 KB |
testcase_05 | AC | 265 ms
120,592 KB |
testcase_06 | AC | 276 ms
120,840 KB |
testcase_07 | AC | 266 ms
120,844 KB |
testcase_08 | AC | 256 ms
120,848 KB |
testcase_09 | AC | 250 ms
120,968 KB |
testcase_10 | AC | 248 ms
120,836 KB |
testcase_11 | AC | 271 ms
120,716 KB |
testcase_12 | AC | 247 ms
120,964 KB |
testcase_13 | AC | 44 ms
54,912 KB |
testcase_14 | AC | 45 ms
54,784 KB |
testcase_15 | AC | 43 ms
54,656 KB |
testcase_16 | AC | 45 ms
54,912 KB |
testcase_17 | AC | 49 ms
54,528 KB |
testcase_18 | AC | 94 ms
77,440 KB |
testcase_19 | AC | 94 ms
77,440 KB |
testcase_20 | AC | 95 ms
77,440 KB |
testcase_21 | AC | 48 ms
59,776 KB |
testcase_22 | AC | 105 ms
77,696 KB |
testcase_23 | AC | 126 ms
79,104 KB |
testcase_24 | AC | 163 ms
89,600 KB |
testcase_25 | AC | 227 ms
110,208 KB |
testcase_26 | AC | 124 ms
79,744 KB |
testcase_27 | AC | 165 ms
87,552 KB |
testcase_28 | AC | 164 ms
87,808 KB |
testcase_29 | AC | 145 ms
81,280 KB |
testcase_30 | AC | 176 ms
92,288 KB |
testcase_31 | AC | 272 ms
114,552 KB |
testcase_32 | AC | 131 ms
81,920 KB |
testcase_33 | AC | 230 ms
106,880 KB |
ソースコード
import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18 LI = lambda : list(map(int, input().split())); II=lambda : int(input()); SI=lambda : [ord(c)-ord("a") for c in input()] def debug(_l_): for s in _l_.split(): print(f"{s}={eval(s)}", end=" ") print() def dlist(*l, fill=0): if len(l)==1: return [fill]*l[0] ll = l[1:] return [dlist(*ll, fill=fill) for _ in range(l[0])] ### セグメント木(はやい) class SG: def __init__(self, n, v=None): self._n = n self.geta = 0 x = 0 while (1 << x) < n: x += 1 self._log = x self._size = 1 << self._log self._d = [ninf] * (2 * self._size) if v is not None: for i in range(self._n): self._d[self._size + i] = v[i] for i in range(self._size - 1, 0, -1): self._update(i) def _update(self, k): self._d[k] = op(self._d[2 * k], self._d[2 * k + 1]) def update(self, p, x): assert 0 <= p < self._n # x -= self.geta p += self._size self._d[p] = x for i in range(1, self._log + 1): # self._update(p >> i) k = p>>i self._d[k] = op(self._d[2 * k], self._d[2 * k + 1]) def get(self, p): assert 0 <= p < self._n return self._d[p + self._size] # + self.geta def check(self): return [self.get(p) for p in range(self._n)] def query(self, left, right): # [l,r)の総和 assert 0 <= left <= right <= self._n sml = ninf smr = ninf left += self._size right += self._size # 外側から計算していく(lは小さい側から, rは大きい側から) while left < right: if left & 1: sml = op(sml, self._d[left]) left += 1 if right & 1: right -= 1 smr = op(self._d[right], smr) left >>= 1 right >>= 1 return op(sml, smr) # + self.geta # def update_all(self, v): # # 全体加算 # self.geta += v def query_all(self): return self._d[1] # + self.geta def max_right(self, left, f): """f(op(a[l], a[l + 1], ..., a[r - 1])) = true となる最大の r -> rはf(op(a[l], ..., a[r]))がFalseになる最小のr """ # assert 0 <= left <= self._n # assert f(ninf) if left == self._n: return self._n left += self._size sm = ninf first = True while first or (left & -left) != left: first = False while left % 2 == 0: left >>= 1 if not f(op(sm, self._d[left])): while left < self._size: left *= 2 if f(op(sm, self._d[left])): sm = op(sm, self._d[left]) left += 1 return left - self._size sm = op(sm, self._d[left]) left += 1 return self._n def min_left(self, right, f): """f(op(a[l], a[l + 1], ..., a[r - 1])) = true となる最小の l -> l は f(op(a[l-1] ,..., a[r-1])) が false になる最大の l """ # assert 0 <= right <= self._n # assert f(ninf) if right == 0: return 0 right += self._size sm = ninf first = True while first or (right & -right) != right: first = False right -= 1 while right > 1 and right % 2: right >>= 1 if not f(op(self._d[right], sm)): while right < self._size: right = 2 * right + 1 if f(op(self._d[right], sm)): sm = op(self._d[right], sm) right -= 1 return right + 1 - self._size sm = op(self._d[right], sm) return 0 op = max ninf = -INF n,k = list(map(int, input().split())) a = LI() a.append(0) cum = [0] for v in a: cum.append(v+cum[-1]) sg = SG(n+2) sg.update(0,0) for i in range(1, n+2): v = a[i-1] val = sg.query(max(0, i-k), i) + cum[i-1] sg.update(i, val - cum[i]) ans = sg.query(n+1,n+2) + cum[n+1] print(ans)