結果

問題 No.2530 Yellow Cards
ユーザー 👑 timitimi
提出日時 2024-02-13 13:38:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,073 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 98,460 KB
最終ジャッジ日時 2024-02-13 13:39:15
合計ジャッジ時間 24,667 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,612 KB
testcase_01 AC 40 ms
55,612 KB
testcase_02 AC 56 ms
70,768 KB
testcase_03 AC 66 ms
72,780 KB
testcase_04 AC 40 ms
55,612 KB
testcase_05 AC 58 ms
70,768 KB
testcase_06 AC 39 ms
55,612 KB
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 AC 1,911 ms
95,880 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 1,944 ms
92,828 KB
testcase_15 AC 1,349 ms
85,916 KB
testcase_16 AC 1,122 ms
84,252 KB
testcase_17 AC 1,975 ms
94,236 KB
testcase_18 AC 460 ms
78,364 KB
testcase_19 AC 147 ms
76,572 KB
testcase_20 AC 461 ms
77,472 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)
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)


0