結果

問題 No.2529 Treasure Hunter
ユーザー KoiKoi
提出日時 2023-11-04 00:04:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 928 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 102,820 KB
最終ジャッジ日時 2023-11-04 00:04:15
合計ジャッジ時間 5,396 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
102,356 KB
testcase_01 WA -
testcase_02 AC 178 ms
102,616 KB
testcase_03 AC 212 ms
102,616 KB
testcase_04 AC 173 ms
102,356 KB
testcase_05 AC 179 ms
102,616 KB
testcase_06 AC 178 ms
102,616 KB
testcase_07 AC 188 ms
102,352 KB
testcase_08 WA -
testcase_09 AC 161 ms
102,356 KB
testcase_10 AC 185 ms
102,352 KB
testcase_11 AC 180 ms
102,352 KB
testcase_12 AC 147 ms
102,356 KB
testcase_13 AC 148 ms
102,360 KB
testcase_14 AC 150 ms
102,360 KB
testcase_15 AC 148 ms
102,360 KB
testcase_16 AC 148 ms
102,360 KB
testcase_17 AC 167 ms
102,356 KB
testcase_18 AC 150 ms
102,356 KB
testcase_19 AC 149 ms
102,360 KB
testcase_20 AC 150 ms
102,360 KB
testcase_21 AC 151 ms
102,360 KB
testcase_22 AC 148 ms
102,360 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
        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