結果

問題 No.1967 Sugoroku Optimization
ユーザー chineristACchineristAC
提出日時 2022-06-03 21:42:26
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 1,966 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 81,808 KB
実行使用メモリ 113,064 KB
最終ジャッジ日時 2023-10-21 01:43:22
合計ジャッジ時間 4,239 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
68,896 KB
testcase_01 AC 62 ms
68,896 KB
testcase_02 AC 64 ms
68,896 KB
testcase_03 AC 164 ms
113,064 KB
testcase_04 AC 171 ms
113,052 KB
testcase_05 AC 166 ms
113,048 KB
testcase_06 AC 166 ms
112,704 KB
testcase_07 AC 165 ms
112,624 KB
testcase_08 AC 141 ms
92,068 KB
testcase_09 AC 165 ms
113,052 KB
testcase_10 AC 110 ms
91,496 KB
testcase_11 AC 127 ms
91,960 KB
testcase_12 AC 164 ms
112,704 KB
testcase_13 AC 141 ms
92,096 KB
testcase_14 AC 167 ms
113,048 KB
testcase_15 AC 115 ms
91,736 KB
testcase_16 AC 112 ms
91,188 KB
testcase_17 AC 87 ms
78,524 KB
testcase_18 AC 87 ms
78,760 KB
testcase_19 AC 63 ms
68,896 KB
testcase_20 AC 165 ms
113,048 KB
testcase_21 AC 63 ms
68,896 KB
testcase_22 AC 167 ms
113,064 KB
testcase_23 AC 166 ms
112,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFindVerSize():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N
        self.group = N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        stack = [x]
        while self._parent[stack[-1]]!=stack[-1]:
            stack.append(self._parent[stack[-1]])
        for v in stack:
            self._parent[v] = stack[-1]
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        self.group -= 1

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
            return gy
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]
            return gx

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    return (g1[n] * g2[r] % mod) * g2[n-r] % mod

mod = 998244353
N = 2*10**5
g1 = [1]*(N+1)
g2 = [1]*(N+1)
inverse = [1]*(N+1)

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

N,K = mi()

dp = [[0 for j in range(N+1)] for i in range(N+1)]
dp[0][0] = 1
for k in range(1,N+1):
    dp[k][0] = 1
    t = 0
    for n in range(1,N+1):
        t += dp[k-1][n-1]
        t %= mod
        dp[k][n] = t * inverse[n] % mod

print(dp[K][N])
0