結果

問題 No.2530 Yellow Cards
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-11-04 12:15:10
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 822 bytes
コンパイル時間 880 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 76,492 KB
最終ジャッジ日時 2023-11-04 12:15:16
合計ジャッジ時間 4,788 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,592 KB
testcase_01 AC 36 ms
53,592 KB
testcase_02 AC 125 ms
76,172 KB
testcase_03 AC 66 ms
75,656 KB
testcase_04 RE -
testcase_05 AC 125 ms
76,172 KB
testcase_06 RE -
testcase_07 AC 239 ms
76,440 KB
testcase_08 AC 235 ms
76,436 KB
testcase_09 AC 235 ms
76,448 KB
testcase_10 AC 235 ms
76,444 KB
testcase_11 AC 238 ms
76,492 KB
testcase_12 AC 237 ms
76,460 KB
testcase_13 AC 235 ms
76,296 KB
testcase_14 AC 221 ms
76,260 KB
testcase_15 AC 182 ms
76,064 KB
testcase_16 AC 145 ms
75,856 KB
testcase_17 AC 221 ms
76,268 KB
testcase_18 AC 90 ms
75,764 KB
testcase_19 AC 55 ms
68,596 KB
testcase_20 AC 105 ms
75,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,input().split())
mod = 998244353

### for bigger prime 
N = n+5
fact = [1]*N
finv = [1]*N
 
for i in range(2,N):
    fact[i] = (fact[i-1]*i)%mod
finv[-1] = pow(fact[-1],mod-2,mod)
for i in range(1,N)[::-1]:
    finv[i-1] = (finv[i]*i)%mod

def nCr(n,r):
    if r > n:
        return 0
    else: 
        return fact[n]*finv[r]%mod*finv[n-r]%mod


dp = [0]*k
dp[0] = 1

for i in range(k):

    ndp = [0]*k

    for j in range(k):
        if dp[j] == 0:
            continue

        yellow = i - j*2

        ndp[j+1] += dp[j] * yellow
        ndp[j+1] %= mod

        if (n-yellow) > 0:
            ndp[j] += dp[j] * (n-yellow)
            ndp[j] %= mod
    
    dp = ndp

ans = 0
for i in range(k):
    ans += (n+i) * dp[i]
    ans %= mod

inv = pow(n,k,mod)
ans *= pow(inv,mod-2,mod)
ans %= mod

print(ans)
0