結果

問題 No.2529 Treasure Hunter
ユーザー timi
提出日時 2024-02-13 11:53:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 414 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 77,280 KB
最終ジャッジ日時 2024-09-28 18:20:38
合計ジャッジ時間 3,857 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

T=int(input())
mod=998244353
for _ in range(T):
  N,M=map(int, input().split())
  dp=[1,N,max(0,N*(N-1)//2-N)]
  for i in range(M-1):
    ndp=[0]*3
    ndp[0]+=sum(dp)
    ndp[1]+=dp[0]*N+dp[1]*(N-1)+dp[2]*(N-2)
    ndp[2]+=dp[0]*max(0,N*(N-1)//2-N)
    ndp[2]+=dp[1]*max(0,(N-1)*(N-2)//2-(N-2))
    ndp[2]+=dp[2]*max(0,(N-2)*(N-3)//2-(N-4))
    dp=ndp
    for j in range(3):
      dp[j]%=mod 
  print(sum(dp)%mod)
0