結果

問題 No.2529 Treasure Hunter
ユーザー 👑 timitimi
提出日時 2024-02-13 11:53:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 414 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2024-02-13 11:53:15
合計ジャッジ時間 5,247 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
72,636 KB
testcase_01 AC 147 ms
76,796 KB
testcase_02 AC 115 ms
76,544 KB
testcase_03 AC 117 ms
76,160 KB
testcase_04 AC 117 ms
76,160 KB
testcase_05 AC 106 ms
75,648 KB
testcase_06 AC 106 ms
75,648 KB
testcase_07 AC 131 ms
76,800 KB
testcase_08 AC 109 ms
75,648 KB
testcase_09 AC 98 ms
75,580 KB
testcase_10 AC 119 ms
76,160 KB
testcase_11 AC 116 ms
76,160 KB
testcase_12 AC 185 ms
76,204 KB
testcase_13 AC 186 ms
76,456 KB
testcase_14 AC 187 ms
76,328 KB
testcase_15 AC 186 ms
76,328 KB
testcase_16 AC 209 ms
76,200 KB
testcase_17 AC 189 ms
76,296 KB
testcase_18 AC 184 ms
76,328 KB
testcase_19 AC 186 ms
76,204 KB
testcase_20 AC 179 ms
76,328 KB
testcase_21 AC 180 ms
76,200 KB
testcase_22 AC 202 ms
76,328 KB
権限があれば一括ダウンロードができます

ソースコード

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