結果
| 問題 |
No.2530 Yellow Cards
|
| コンテスト | |
| ユーザー |
timi
|
| 提出日時 | 2024-02-13 13:38:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,774 ms / 2,000 ms |
| コード長 | 1,073 bytes |
| コンパイル時間 | 554 ms |
| コンパイル使用メモリ | 82,572 KB |
| 実行使用メモリ | 99,088 KB |
| 最終ジャッジ日時 | 2024-09-28 18:21:32 |
| 合計ジャッジ時間 | 19,726 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
ソースコード
mod=998244353
N,K=map(int, input().split())
def xgcd(a, b):
x0, y0, x1, y1 = 1, 0, 0, 1
while b != 0:
q, a, b = a // b, b, a % b
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
return a, x0, y0
def modinv(a, m):
g, x, y = xgcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
def f(x,y):
return x*10000+y
def ff(z):
x,y=z//10000,z%10000
return x,y
gt=modinv(N,mod)
from collections import deque
d=deque()
d.append(0)
D={}
D[0]=1
for i in range(K):
nd=deque();DD={}
while d:
dd=d.popleft()
r,y=ff(dd)
p=N-y
c=D[f(r,y)]
if y!=0:
nex=f(r+1,y-1)
a=(y*gt*c)%mod
if nex not in DD:
DD[nex]=0
nd.append(nex)
DD[nex]+=a
DD[nex]%=mod
if p!=0:
a=(p*gt*c)%mod
nex=f(r,y+1)
if nex not in DD:
DD[nex]=0
nd.append(nex)
DD[nex]+=a
DD[nex]%=mod
d=nd
D=DD
ans=0
for d in D:
r,y=ff(d)
p=N-y
c=r+y+p
ans+=c*D[d]
ans%=mod
print(ans)
timi