結果

問題 No.2530 Yellow Cards
ユーザー 👑 timitimi
提出日時 2024-02-13 14:03:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,212 bytes
コンパイル時間 2,325 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 276,288 KB
最終ジャッジ日時 2024-02-13 14:04:16
合計ジャッジ時間 23,882 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,612 KB
testcase_01 AC 37 ms
55,612 KB
testcase_02 AC 55 ms
70,660 KB
testcase_03 AC 57 ms
70,676 KB
testcase_04 WA -
testcase_05 AC 52 ms
70,660 KB
testcase_06 WA -
testcase_07 AC 1,927 ms
276,288 KB
testcase_08 AC 1,900 ms
276,160 KB
testcase_09 AC 1,893 ms
276,288 KB
testcase_10 AC 1,946 ms
275,904 KB
testcase_11 AC 1,775 ms
274,880 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 1,587 ms
216,512 KB
testcase_15 AC 1,123 ms
165,360 KB
testcase_16 AC 1,023 ms
167,360 KB
testcase_17 AC 1,717 ms
229,312 KB
testcase_18 AC 431 ms
134,848 KB
testcase_19 AC 138 ms
90,432 KB
testcase_20 AC 354 ms
97,088 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):
  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,0))
dp=[[0]*(N+1) for i in range(K//2+1)]
V=[[0]*(N+1) for i in range(K//2+1)]
dp[0][0]=1;V[0][0]=1
for i in range(K):
  nd=deque();DD={}
  while d:
    r,y=d.popleft()
    p=N-y
    c=dp[r][y]
    if y!=0:
      a=(y*gt*c)%mod
      if V[r+1][y-1]==0:
        V[r+1][y-1]=i+1
        nd.append((r+1,y-1))
      dp[r+1][y-1]+=a
      dp[r+1][y-1]%=mod 
    if p!=0:
      a=(p*gt*c)%mod
      if V[r][y+1]==0:
        V[r][y+1]=i+1
        nd.append((r,y+1))
      dp[r][y+1]+=a
      dp[r][y+1]%=mod
  d=nd 
  D=DD
  


ans=0
for r in range(K//2+1):
  for y in range(N+1):
    if V[r][y]==K:
      p=N-y
      c=r+y+p
      ans+=c*dp[r][y]
      ans%=mod
print(ans)
    

0