結果
問題 |
No.2530 Yellow Cards
|
ユーザー |
![]() |
提出日時 | 2024-02-13 15:23:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,674 ms / 2,000 ms |
コード長 | 1,192 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 82,296 KB |
実行使用メモリ | 277,276 KB |
最終ジャッジ日時 | 2024-09-28 18:24:20 |
合計ジャッジ時間 | 16,879 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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): e=N+1 return x*e+y def ff(z): e=N+1 x,y=z//e,z//e return x,y gt=modinv(N,mod) from collections import deque d=deque() d.append((0,0)) dp=[0]*(N+1)*(K//2+10) V=[-1]*(N+1)*(K//2+10) dp[0]=1;V[0]=0 for i in range(K): nd=deque();DD={} while d: r,y=d.popleft() p=N-y c=dp[f(r,y)] if y!=0: nex=f(r+1,y-1) a=(y*gt*c)%mod if V[nex]==-1: V[nex]=i+1 nd.append((r+1,y-1)) dp[nex]+=a dp[nex]%=mod if p!=0: a=(p*gt*c)%mod nex=f(r,y+1) if V[nex]==-1: V[nex]=i+1 nd.append((r,y+1)) dp[nex]+=a dp[nex]%=mod d=nd ans=0 for r in range(K//2+1): for y in range(N+1): cc=f(r,y) if V[cc]==K: p=N-y c=r+y+p ans+=c*dp[cc] ans%=mod print(ans)