結果

問題 No.2530 Yellow Cards
ユーザー nikoro256nikoro256
提出日時 2023-11-03 23:27:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,185 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 271,904 KB
最終ジャッジ日時 2023-11-03 23:27:26
合計ジャッジ時間 13,958 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,596 KB
testcase_01 AC 33 ms
53,596 KB
testcase_02 AC 364 ms
271,896 KB
testcase_03 AC 91 ms
90,400 KB
testcase_04 AC 32 ms
53,596 KB
testcase_05 AC 375 ms
271,896 KB
testcase_06 AC 36 ms
53,596 KB
testcase_07 AC 1,184 ms
271,896 KB
testcase_08 AC 1,034 ms
271,904 KB
testcase_09 AC 1,168 ms
271,856 KB
testcase_10 AC 1,103 ms
271,708 KB
testcase_11 AC 913 ms
271,604 KB
testcase_12 AC 1,185 ms
271,900 KB
testcase_13 AC 1,157 ms
271,392 KB
testcase_14 AC 1,071 ms
260,820 KB
testcase_15 AC 729 ms
225,028 KB
testcase_16 AC 619 ms
173,228 KB
testcase_17 AC 1,087 ms
255,116 KB
testcase_18 AC 261 ms
112,272 KB
testcase_19 AC 91 ms
82,212 KB
testcase_20 AC 351 ms
173,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(a, b):
    if b:
        d, y, x = extgcd(b, a % b)
        y -= (a // b) * x
        return d, x, y
    return a, 1, 0

#以下modinv
def mod_inv(a, m):
    g, x, y = extgcd(a, m)

    if g != 1:
        raise Exception()

    if x < 0:
        x += m

    return x

N,K=map(int,input().split())
dp=[[0 for _ in range(K+1)] for _ in range(K+1)]
#dp[イエローカード提示数][人が抜けた数]
dp[0][0]=1
p=998244353
inv=mod_inv(N,p)
for i in range(K):
    for j in range(i//2+1):
        dp[i+1][j]+=dp[i][j]*inv*(N-(i-j*2))%p
        dp[i+1][j]%=p
        dp[i+1][j+1]+=dp[i][j]*inv*(i-j*2)%p
        dp[i+1][j+1]%=p
ans=0
for j in range(K+1):
    ans+=(N+j)*dp[-1][j]
    ans%=p
print(ans)
0