結果

問題 No.2529 Treasure Hunter
ユーザー cho435cho435
提出日時 2023-11-03 22:37:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,140 bytes
コンパイル時間 3,894 ms
コンパイル使用メモリ 268,844 KB
実行使用メモリ 14,312 KB
最終ジャッジ日時 2023-11-03 22:37:52
合計ジャッジ時間 5,610 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

int main(){
	int t;
	cin>>t;
	rep(Ti,t){
		ll n,m;
		cin>>n>>m;
		if(n<=3){
			vector<vector<mint>> dp(m+1,vector<mint>(3,0));
			dp.at(0).at(0)=1;
			rep(i,m){
				dp.at(i+1).at(0)=dp.at(i).at(0)+dp.at(i).at(1)+dp.at(i).at(2);
				dp.at(i+1).at(1)+=dp.at(i).at(0)*n;
				dp.at(i+1).at(1)+=dp.at(i).at(1)*(n-1);
				dp.at(i+1).at(1)+=dp.at(i).at(2)*(n-2);
			}
			mint ans=0;
			rep(i,3) ans+=dp.at(m).at(i);
			cout<<ans.val()<<"\n";
			continue;
		}
		vector<vector<mint>> dp(m+1,vector<mint>(3,0));
		dp.at(0).at(0)=1;
		rep(i,m){
			dp.at(i+1).at(0)=dp.at(i).at(0)+dp.at(i).at(1)+dp.at(i).at(2);
			dp.at(i+1).at(1)+=dp.at(i).at(0)*n;
			dp.at(i+1).at(1)+=dp.at(i).at(1)*(n-1);
			dp.at(i+1).at(1)+=dp.at(i).at(2)*(n-2);
			dp.at(i+1).at(2)+=dp.at(i).at(0)*n*(n-3)/2;
			dp.at(i+1).at(2)+=dp.at(i).at(1)*(n*(n-3)/2-(n-3));
			dp.at(i+1).at(2)+=dp.at(i).at(2)*(n*(n-3)/2-(2*n-7));
		}
		mint ans=0;
		rep(i,3) ans+=dp.at(m).at(i);
		cout<<ans.val()<<"\n";
	}
}
0