結果

問題 No.2529 Treasure Hunter
ユーザー KoiKoi
提出日時 2023-11-04 00:08:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 102,840 KB
最終ジャッジ日時 2023-11-04 00:08:16
合計ジャッジ時間 5,550 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
102,376 KB
testcase_01 AC 198 ms
102,840 KB
testcase_02 AC 151 ms
102,372 KB
testcase_03 AC 162 ms
102,636 KB
testcase_04 AC 153 ms
102,376 KB
testcase_05 AC 156 ms
102,636 KB
testcase_06 AC 158 ms
102,636 KB
testcase_07 AC 192 ms
102,636 KB
testcase_08 AC 176 ms
102,636 KB
testcase_09 AC 141 ms
102,376 KB
testcase_10 AC 162 ms
102,636 KB
testcase_11 AC 156 ms
102,372 KB
testcase_12 AC 131 ms
102,380 KB
testcase_13 AC 129 ms
102,380 KB
testcase_14 AC 129 ms
102,380 KB
testcase_15 AC 130 ms
102,380 KB
testcase_16 AC 145 ms
102,380 KB
testcase_17 AC 130 ms
102,380 KB
testcase_18 AC 130 ms
102,380 KB
testcase_19 AC 139 ms
102,380 KB
testcase_20 AC 130 ms
102,380 KB
testcase_21 AC 132 ms
102,380 KB
testcase_22 AC 134 ms
102,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Mod=998244353
T=int(input())
answers=[]
Mod=998244353
facts_max=2*10**5
facts=[]
inv_facts=[]
t=1
for i in range(facts_max+1):
    facts.append(t)
    t=t*(i+1)%Mod
inv_facts.append(pow(facts[facts_max],-1,Mod))
for i in range(facts_max):
    inv_facts.append(inv_facts[-1]*(facts_max-i)%Mod)
inv_facts.reverse()
def comb(n,k):
    if(n<k or n<0):
        return 0
    return facts[n]*inv_facts[k]*inv_facts[n-k]%Mod
for i in range(T):
    N,M=map(int,input().split())
    dp=[1,0,0]
    for i in range(M):
        new_dp=[0]*3
        new_dp[0]=(dp[0]+dp[1]+dp[2])%Mod
        new_dp[1]=(dp[0]*N+dp[1]*(N-1)+dp[2]*(N-2))%Mod
        if(N>2):
            new_dp[2]+=dp[0]*(comb(N,2)-N)
        if(N>=3):
            new_dp[2]+=dp[1]*(comb(N-1,2)-(N-1)+1)
        if(N>=4):
            new_dp[2]+=dp[2]*(comb(N-3,2)-(N-3)+1+N-3)
        dp=[_%Mod for _ in new_dp]
        # print(dp)
    answers.append(sum(dp)%Mod)
for ans in answers:
    print(ans)
0