結果

問題 No.2529 Treasure Hunter
ユーザー 沙耶花沙耶花
提出日時 2023-11-03 21:44:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,515 bytes
コンパイル時間 4,266 ms
コンパイル使用メモリ 269,704 KB
実行使用メモリ 28,056 KB
最終ジャッジ日時 2023-11-03 21:44:32
合計ジャッジ時間 6,717 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001
struct combi{
	deque<mint> kaijou;
	deque<mint> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(kaijou[i-1]*i);
		}
		
		mint b=kaijou[n].inv();
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(kaijou_[0]*k);
		}
	}
	
	mint combination(int n,int r){
		if(r>n)return 0;
		mint a = kaijou[n]*kaijou_[r];
		a *= kaijou_[n-r];
		return a;
	}
	
	mint junretsu(int a,int b){
		mint x = kaijou_[a]*kaijou_[b];
		x *= kaijou[a+b];
		return x;
	}
	
	mint catalan(int n){
		return combination(2*n,n)/(n+1);
	}
	
};


combi C(3000000);
int main(){
	
	int _t;
	cin>>_t;
	
	rep(_,_t){
		
		int n,m;
		cin>>n>>m;
		
		swap(n,m);
		vector<mint> dp(3,0);
		dp[0] = 1;
		rep(i,n){
			vector<mint> ndp(3,0);
			ndp[0] += dp[0]+dp[1]+dp[2];
			ndp[1] += dp[0]*m + dp[1]*(m-1) + dp[2]*(m-2);
			
			
			{
				mint t = C.combination(m,2);
				t -= m;
				t *= dp[0];
				ndp[2] += t;
			}
			
			{
				mint t = C.combination(m-1,2);
				t -= m-2;
				t *= dp[1];
				ndp[2] += t;
			}
			
			if(m>=4){
				mint t = C.combination(m-2,2);
				t -= m-4;
				t *= dp[2];
				ndp[2] += t;
			}
			
			swap(dp,ndp);
		}
		mint ans = 0;
		rep(i,3)ans += dp[i];
		cout<<ans.val()<<endl;
		
	}
	
	return 0;
}
0