結果

問題 No.2529 Treasure Hunter
ユーザー 👑 hitonanodehitonanode
提出日時 2023-11-03 22:14:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 83,076 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 22:14:14
合計ジャッジ時間 1,605 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

mint solve(int T, int M) {

    mint a02 = mint(M) * (M - 1) / 2 - M;
    mint a12 = a02 - (M - 3);
    mint a22 = a02 - (M - 3) * 2 + 1;

    mint v0 = 1, v1 = 0, v2 = 0;

    while (T--) {
        mint nv0 = v0 + v1 + v2;
        mint nv1 = v0 * M + v1 * (M - 1) + v2 * (M - 2);
        mint nv2 = v0 * a02 + v1 * a12 + v2 * a22;

        if (M <= 3) nv2 = 0;

        v0 = nv0, v1 = nv1, v2 = nv2;
    }
    return v0 + v1 + v2;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int T;
    cin >> T;
    while (T--) {
        int N, M;
        cin >> M >> N;
        cout << solve(N, M).val() << '\n';
    }
}
0