結果

問題 No.2529 Treasure Hunter
ユーザー momoyuumomoyuu
提出日時 2023-11-04 22:39:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 3,974 ms
コンパイル使用メモリ 253,868 KB
実行使用メモリ 16,352 KB
最終ジャッジ日時 2023-11-04 22:39:08
合計ジャッジ時間 6,882 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
5,808 KB
testcase_01 AC 104 ms
5,708 KB
testcase_02 AC 95 ms
5,820 KB
testcase_03 AC 103 ms
5,808 KB
testcase_04 AC 102 ms
5,824 KB
testcase_05 AC 102 ms
5,832 KB
testcase_06 AC 102 ms
5,820 KB
testcase_07 AC 102 ms
5,792 KB
testcase_08 AC 101 ms
5,812 KB
testcase_09 AC 88 ms
5,792 KB
testcase_10 AC 101 ms
5,800 KB
testcase_11 AC 101 ms
5,792 KB
testcase_12 AC 101 ms
15,824 KB
testcase_13 AC 104 ms
16,088 KB
testcase_14 AC 104 ms
15,824 KB
testcase_15 AC 103 ms
15,824 KB
testcase_16 AC 105 ms
16,088 KB
testcase_17 AC 104 ms
16,088 KB
testcase_18 AC 103 ms
15,824 KB
testcase_19 AC 105 ms
16,088 KB
testcase_20 AC 104 ms
16,088 KB
testcase_21 AC 105 ms
16,088 KB
testcase_22 AC 107 ms
16,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;


#include<atcoder/modint>
using mint = atcoder::modint998244353;

const int mx = 2<<17;
mint fac[mx+1],ifac[mx+1];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>m>>n;
        vector<vector<mint>> dp(n+1,vector<mint>(3,0));
        dp[0][0] = 1;
        for(int i = 0;i<n;i++){
            dp[i+1][0] += dp[i][0] + dp[i][1] + dp[i][2];
            if(m>3){
                mint tmp = mint(m) * mint(m-1) / mint(2);
                tmp -= m;
                dp[i+1][2] += tmp * dp[i][0];
                tmp = mint(m-1) * mint(m-2) / mint(2);
                tmp -= m - 2;
                dp[i+1][2] += tmp * dp[i][1];
                tmp = mint(m-2) * mint(m-3) / mint(2);
                tmp -= m - 4;
                dp[i+1][2] += tmp * dp[i][2];
            }
            dp[i+1][1] += mint(m) * dp[i][0];
            dp[i+1][1] += mint(m-1) * dp[i][1];
            dp[i+1][1] += mint(m-2) * dp[i][2];
        }
        mint ans = dp[n][0] + dp[n][1] + dp[n][2];
        cout<<ans.val()<<endl;
    }
}
0