結果

問題 No.1967 Sugoroku Optimization
ユーザー rlangevinrlangevin
提出日時 2023-04-27 20:38:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 810 ms / 2,000 ms
コード長 1,448 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,972 KB
実行使用メモリ 83,328 KB
最終ジャッジ日時 2024-04-28 10:52:24
合計ジャッジ時間 8,313 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,380 KB
testcase_01 AC 36 ms
52,996 KB
testcase_02 AC 37 ms
53,600 KB
testcase_03 AC 810 ms
83,328 KB
testcase_04 AC 59 ms
67,676 KB
testcase_05 AC 738 ms
82,844 KB
testcase_06 AC 786 ms
83,128 KB
testcase_07 AC 72 ms
76,492 KB
testcase_08 AC 540 ms
80,952 KB
testcase_09 AC 425 ms
79,796 KB
testcase_10 AC 253 ms
77,060 KB
testcase_11 AC 109 ms
76,760 KB
testcase_12 AC 508 ms
80,800 KB
testcase_13 AC 291 ms
78,684 KB
testcase_14 AC 85 ms
76,296 KB
testcase_15 AC 96 ms
76,344 KB
testcase_16 AC 103 ms
76,452 KB
testcase_17 AC 87 ms
76,000 KB
testcase_18 AC 55 ms
68,240 KB
testcase_19 AC 39 ms
53,804 KB
testcase_20 AC 755 ms
83,232 KB
testcase_21 AC 36 ms
52,712 KB
testcase_22 AC 783 ms
83,256 KB
testcase_23 AC 511 ms
80,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
            self.data[p - 1] %= mod
            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]
            s %= mod
            r -= r & -r
        return s % mod
    
    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
    
    
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 = Fenwick_Tree(N + 1)
ans = 0
pre.add(0, 1)
pre.add(1, -1)
for k in range(K):
    now = Fenwick_Tree(N + 1)
    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.sum(0, i + 1) % mod
        now.add(i + 1, v)
        ans += v
        ans %= mod
    pre, now = now, pre
    
print(ans) 
0