結果

問題 No.2530 Yellow Cards
ユーザー 👑 timitimi
提出日時 2024-02-13 15:23:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,804 ms / 2,000 ms
コード長 1,192 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 276,696 KB
最終ジャッジ日時 2024-02-13 15:23:52
合計ジャッジ時間 18,193 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,608 KB
testcase_01 AC 39 ms
55,608 KB
testcase_02 AC 56 ms
70,632 KB
testcase_03 AC 64 ms
72,752 KB
testcase_04 AC 39 ms
55,608 KB
testcase_05 AC 55 ms
70,632 KB
testcase_06 AC 43 ms
62,360 KB
testcase_07 AC 1,804 ms
276,696 KB
testcase_08 AC 1,509 ms
276,280 KB
testcase_09 AC 1,596 ms
276,616 KB
testcase_10 AC 1,584 ms
276,332 KB
testcase_11 AC 1,321 ms
275,408 KB
testcase_12 AC 1,595 ms
276,368 KB
testcase_13 AC 1,569 ms
276,056 KB
testcase_14 AC 1,381 ms
216,580 KB
testcase_15 AC 897 ms
165,372 KB
testcase_16 AC 825 ms
167,424 KB
testcase_17 AC 1,458 ms
229,488 KB
testcase_18 AC 343 ms
134,780 KB
testcase_19 AC 131 ms
90,468 KB
testcase_20 AC 354 ms
97,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
    

0