結果

問題 No.2529 Treasure Hunter
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-04-02 01:14:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 957 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 208,728 KB
実行使用メモリ 14,156 KB
最終ジャッジ日時 2024-04-02 01:14:50
合計ジャッジ時間 3,892 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 WA -
testcase_02 AC 13 ms
6,676 KB
testcase_03 AC 14 ms
6,676 KB
testcase_04 AC 14 ms
6,676 KB
testcase_05 AC 15 ms
6,676 KB
testcase_06 AC 15 ms
6,676 KB
testcase_07 AC 13 ms
6,676 KB
testcase_08 WA -
testcase_09 AC 13 ms
6,676 KB
testcase_10 AC 15 ms
6,676 KB
testcase_11 AC 15 ms
6,676 KB
testcase_12 AC 19 ms
13,644 KB
testcase_13 AC 20 ms
13,952 KB
testcase_14 AC 20 ms
13,868 KB
testcase_15 AC 19 ms
13,812 KB
testcase_16 AC 21 ms
14,072 KB
testcase_17 AC 21 ms
13,912 KB
testcase_18 AC 20 ms
13,784 KB
testcase_19 AC 20 ms
14,044 KB
testcase_20 AC 20 ms
13,960 KB
testcase_21 AC 20 ms
14,080 KB
testcase_22 AC 21 ms
14,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint998244353;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<mint>> dp(m, vector<mint>(3));
    long long c1 = max((long long)n * (n - 3) / 2, 0LL);
    long long c2 = max(c1 - n + 3, 0LL);
    long long c3 = max(c1 - 2 * n + 7, 0LL);
    dp[0][0] = 1;
    dp[0][1] = n;
    dp[0][2] = c1;

    for (int i = 1; i < m; i++) {
        dp[i][0] = dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2];
        dp[i][1] =
            n * dp[i - 1][0] + (n - 1) * dp[i - 1][1] + (n - 2) * dp[i - 1][2];
        dp[i][2] = c1 * dp[i - 1][0] + c2 * dp[i - 1][1] + c3 * dp[i - 1][2];
    }
    mint ans = dp[m - 1][0] + dp[m - 1][1] + dp[m - 1][2];
    cout << ans.val() << "\n";
}
int main() {
    fast_io();
    int t;
    cin >> t;
    for (; t--;) {
        solve();
    }
}
0