結果

問題 No.2529 Treasure Hunter
ユーザー t98slidert98slider
提出日時 2023-11-04 01:29:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 794 bytes
コンパイル時間 4,899 ms
コンパイル使用メモリ 266,544 KB
実行使用メモリ 14,232 KB
最終ジャッジ日時 2023-11-04 01:29:17
合計ジャッジ時間 5,954 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,372 KB
testcase_01 AC 16 ms
4,372 KB
testcase_02 AC 16 ms
4,372 KB
testcase_03 AC 17 ms
4,372 KB
testcase_04 AC 17 ms
4,372 KB
testcase_05 AC 16 ms
4,372 KB
testcase_06 AC 17 ms
4,372 KB
testcase_07 AC 17 ms
4,372 KB
testcase_08 AC 17 ms
4,372 KB
testcase_09 AC 15 ms
4,372 KB
testcase_10 AC 17 ms
4,372 KB
testcase_11 AC 17 ms
4,372 KB
testcase_12 AC 21 ms
13,704 KB
testcase_13 AC 21 ms
13,968 KB
testcase_14 AC 21 ms
13,968 KB
testcase_15 AC 20 ms
13,704 KB
testcase_16 AC 21 ms
13,968 KB
testcase_17 AC 21 ms
13,968 KB
testcase_18 AC 21 ms
13,704 KB
testcase_19 AC 21 ms
13,968 KB
testcase_20 AC 21 ms
13,968 KB
testcase_21 AC 21 ms
13,968 KB
testcase_22 AC 21 ms
14,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    mint div = mint(1) / 2;
    while(T--){
        long long n, m;
        cin >> n >> m;
        vector dp(m, vector<mint>(3));
        dp[0][0] = 1;
        dp[0][1] = n;
        if(n >= 4) dp[0][2] = n * (n - 3) / 2;
        for(int i = 0; i + 1 < m; i++){
            for(int j = 0; j < 3; j++){
                dp[i + 1][0] += dp[i][j];
                dp[i + 1][1] += (n - j) * dp[i][j];
                if(n >= 4) dp[i + 1][2] += ((n - j) * (n - j - 1) / 2 - (n - 2 * j)) * dp[i][j];
            }
        }
        cout << (dp[m - 1][0] + dp[m - 1][1] + dp[m - 1][2]).val() << '\n';
    }
}
0