結果
問題 | No.1967 Sugoroku Optimization |
ユーザー | rlangevin |
提出日時 | 2023-04-27 12:43:24 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,420 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 317,676 KB |
最終ジャッジ日時 | 2024-11-16 20:09:31 |
合計ジャッジ時間 | 31,922 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
57,600 KB |
testcase_01 | AC | 38 ms
188,292 KB |
testcase_02 | AC | 38 ms
58,496 KB |
testcase_03 | TLE | - |
testcase_04 | AC | 111 ms
82,688 KB |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | AC | 174 ms
219,552 KB |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | AC | 1,256 ms
114,284 KB |
testcase_11 | AC | 342 ms
82,228 KB |
testcase_12 | TLE | - |
testcase_13 | AC | 1,451 ms
116,412 KB |
testcase_14 | AC | 251 ms
79,612 KB |
testcase_15 | AC | 283 ms
80,968 KB |
testcase_16 | AC | 346 ms
82,608 KB |
testcase_17 | AC | 325 ms
79,684 KB |
testcase_18 | AC | 164 ms
77,668 KB |
testcase_19 | AC | 54 ms
61,184 KB |
testcase_20 | TLE | - |
testcase_21 | AC | 41 ms
52,352 KB |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
ソースコード
class LazySegmentTree: def __init__( self, n, indentity_e_node, indentity_e_lazy, combine_node_f, combine_lazy_f, reflect_f, ): self._n = n self._size = 1 self._height = 0 while self._size < self._n: self._size <<= 1 self._height += 1 self._indentity_e_node = indentity_e_node self._indentity_e_lazy = indentity_e_lazy self._combine_node_f = combine_node_f self._combine_lazy_f = combine_lazy_f self._reflect_f = reflect_f self._node = [self._indentity_e_node] * (2 * self._size) self._lazy = [self._indentity_e_lazy] * (2 * self._size) #遅延データの値を値データに反映させたときの値を返す。 def _reflect_lazy(self, index): return self._reflect_f(self._node[index], self._lazy[index]) def _propagate_from_top(self, index): index += self._size for h in range(self._height, 0, -1): i = index >> h if self._lazy[i] != self._indentity_e_lazy: self._lazy[i << 1] = self._combine_lazy_f( self._lazy[i << 1], self._lazy[i] ) self._lazy[i << 1 | 1] = self._combine_lazy_f( self._lazy[i << 1 | 1], self._lazy[i] ) self._node[i] = self._reflect_lazy(i) self._lazy[i] = self._indentity_e_lazy def _update_from_bottom(self, index): index = (index + self._size) >> 1 while index: self._node[index] = self._combine_node_f( self._reflect_lazy(index << 1), self._reflect_lazy(index << 1 | 1) ) index >>= 1 def build(self, array): assert len(array) == self._n for index, value in enumerate(array, start=self._size): self._node[index] = value for index in range(self._size - 1, 0, -1): self._node[index] = self._combine_node_f( self._node[index << 1], self._node[index << 1 | 1] ) # 区間更新 位置[L, R) (0-indexed)を値valueで更新 def update(self, L, R, value): self._propagate_from_top(L) self._propagate_from_top(R - 1) L_lazy = L + self._size R_lazy = R + self._size while L_lazy < R_lazy: if L_lazy & 1: self._lazy[L_lazy] = self._combine_lazy_f(self._lazy[L_lazy], value) L_lazy += 1 if R_lazy & 1: R_lazy -= 1 self._lazy[R_lazy] = self._combine_lazy_f(self._lazy[R_lazy], value) L_lazy >>= 1 R_lazy >>= 1 self._update_from_bottom(L) self._update_from_bottom(R - 1) # 区間取得 区間[L, R) (0-indexed)内の要素について # L番目から順にcombine_node_fを適用した値を返す。 def fold(self, L, R): self._propagate_from_top(L) self._propagate_from_top(R - 1) L += self._size R += self._size value_L = self._indentity_e_node value_R = self._indentity_e_node while L < R: if L & 1: value_L = self._combine_node_f(value_L, self._reflect_lazy(L)) value_L %= mod L += 1 if R & 1: R -= 1 value_R = self._combine_node_f(value_R, self._reflect_lazy(R)) value_R %= mod L >>= 1 R >>= 1 return self._combine_node_f(value_L, value_R) N, K = map(int, input().split()) inv = [1] * (N + 1) mod = 998244353 for i in range(1, N + 1): inv[i] = pow(i, mod - 2, mod) # pre = [0] * (N + 1) # pre[0] = 1 pre = LazySegmentTree(N + 1, 0, 0, max, lambda x, y:(x+y)%mod, lambda x, y:(x+y)%mod) ans = 0 pre.update(0, 1, 1) for k in range(K): now = LazySegmentTree(N + 1, 0, 0, max, lambda x, y:(x+y)%mod, lambda x, y:(x+y)%mod) for i in range(N): # for j in range(i + 1, N + 1): # now[j] += inv[N - i] * pre[i] v = inv[N - i] * pre.fold(i, i + 1) % mod now.update(i + 1, N + 1, v) ans += v ans %= mod pre, now = now, pre print(ans)