結果

問題 No.2529 Treasure Hunter
ユーザー ripityripity
提出日時 2023-11-03 22:59:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 614 bytes
コンパイル時間 5,456 ms
コンパイル使用メモリ 266,764 KB
実行使用メモリ 14,344 KB
最終ジャッジ日時 2023-11-03 22:59:21
合計ジャッジ時間 4,955 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

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

void solve() {
	long long N, M;
	cin >> M >> N;
	vector<vector<mint>> dp(N+1, vector<mint>(3));
	dp[0][0] = 1;
	for( int i = 1; i <= N; i++ ) {
		dp[i][0] = dp[i-1][0]+dp[i-1][1]+dp[i-1][2];
		dp[i][1] = dp[i-1][0]*M+dp[i-1][1]*(M-1)+dp[i-1][2]*(M-2);
		dp[i][2] = dp[i-1][0]*max(0LL, M*(M-3)/2)+dp[i-1][1]*max(0LL, (M-2)*(M-3)/2)+dp[i-1][2]*max(0LL, (M*M-7*M+14)/2);
	}
	cout << accumulate(dp[N].begin(), dp[N].end(), mint(0)).val() << endl;
}

int main() {
	int T;
	cin >> T;
	while(T--) { solve(); }
}
0