結果

問題 No.2529 Treasure Hunter
ユーザー otoshigootoshigo
提出日時 2023-11-03 22:14:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 765 ms
コンパイル使用メモリ 83,248 KB
実行使用メモリ 37,516 KB
最終ジャッジ日時 2023-11-03 22:14:25
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
27,188 KB
testcase_01 AC 17 ms
27,092 KB
testcase_02 AC 18 ms
27,204 KB
testcase_03 AC 18 ms
27,192 KB
testcase_04 AC 18 ms
27,208 KB
testcase_05 AC 19 ms
27,216 KB
testcase_06 AC 18 ms
27,204 KB
testcase_07 AC 18 ms
27,176 KB
testcase_08 AC 19 ms
27,196 KB
testcase_09 AC 16 ms
27,176 KB
testcase_10 AC 18 ms
27,184 KB
testcase_11 AC 17 ms
27,176 KB
testcase_12 AC 23 ms
36,988 KB
testcase_13 AC 24 ms
37,516 KB
testcase_14 AC 21 ms
37,252 KB
testcase_15 AC 22 ms
37,252 KB
testcase_16 AC 22 ms
37,516 KB
testcase_17 AC 22 ms
37,252 KB
testcase_18 AC 22 ms
37,252 KB
testcase_19 AC 22 ms
37,516 KB
testcase_20 AC 23 ms
37,516 KB
testcase_21 AC 22 ms
37,516 KB
testcase_22 AC 23 ms
37,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;
using ll=long long;
using mint=modint998244353;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const int MAX=2000010;
const ll MOD=998244353;
mint fac[MAX+1],finv[MAX+1],inv[MAX+1];

void set_fac(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2;i<=MAX;i++){
        fac[i]=fac[i-1]*i;
        inv[i]=-inv[MOD%i]*(MOD/i);
        finv[i]=finv[i-1]*inv[i];
    }
}

mint cmb(int n,int r){
    if (r<0||n<r)return 0;
    return fac[n]*finv[r]*finv[n-r];
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--){
        ll N,M;
        cin>>N>>M;
        vector dp(M+1,vector<mint>(3));
        dp[0][0]=1;
        for(int i=0;i<M;i++){
            dp[i+1][0]+=dp[i][0]+dp[i][1]+dp[i][2];
            dp[i+1][1]+=dp[i][0]*N+dp[i][1]*(N-1)+dp[i][2]*(N-2);
            if(N>=4){
                dp[i+1][2]+=dp[i][0]*(N*(N-1)/2-N);
                dp[i+1][2]+=dp[i][1]*(N*(N-1)/2-N-(N-3));
                dp[i+1][2]+=dp[i][2]*(N*(N-1)/2-N-2*(N-3)+1);
            }
        }
        mint ans=dp[M][0]+dp[M][1]+dp[M][2];
        cout<<ans.val()<<"\n";
    }
}
0