結果

問題 No.2484 Add to Variables
ユーザー shobonvipshobonvip
提出日時 2023-09-22 22:47:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 2,167 bytes
コンパイル時間 5,068 ms
コンパイル使用メモリ 269,564 KB
実行使用メモリ 20,212 KB
最終ジャッジ日時 2023-09-22 22:47:31
合計ジャッジ時間 8,307 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
11,284 KB
testcase_01 AC 14 ms
11,168 KB
testcase_02 AC 13 ms
11,236 KB
testcase_03 AC 14 ms
11,184 KB
testcase_04 AC 15 ms
11,176 KB
testcase_05 AC 14 ms
11,272 KB
testcase_06 AC 14 ms
11,172 KB
testcase_07 AC 14 ms
11,416 KB
testcase_08 AC 15 ms
11,172 KB
testcase_09 AC 14 ms
11,252 KB
testcase_10 AC 21 ms
11,732 KB
testcase_11 AC 28 ms
12,292 KB
testcase_12 AC 41 ms
13,160 KB
testcase_13 AC 41 ms
12,988 KB
testcase_14 AC 69 ms
15,388 KB
testcase_15 AC 21 ms
11,700 KB
testcase_16 AC 42 ms
13,376 KB
testcase_17 AC 18 ms
11,408 KB
testcase_18 AC 41 ms
13,372 KB
testcase_19 AC 73 ms
17,028 KB
testcase_20 AC 18 ms
11,348 KB
testcase_21 AC 129 ms
19,280 KB
testcase_22 AC 20 ms
11,512 KB
testcase_23 AC 42 ms
13,288 KB
testcase_24 AC 73 ms
17,048 KB
testcase_25 AC 69 ms
15,080 KB
testcase_26 AC 43 ms
13,924 KB
testcase_27 AC 43 ms
13,940 KB
testcase_28 AC 70 ms
15,312 KB
testcase_29 AC 70 ms
15,336 KB
testcase_30 AC 27 ms
12,240 KB
testcase_31 AC 97 ms
16,624 KB
testcase_32 AC 70 ms
16,036 KB
testcase_33 AC 131 ms
20,212 KB
testcase_34 AC 42 ms
13,224 KB
testcase_35 AC 95 ms
16,160 KB
testcase_36 AC 42 ms
13,660 KB
testcase_37 AC 71 ms
16,080 KB
testcase_38 AC 69 ms
15,436 KB
testcase_39 AC 71 ms
15,712 KB
testcase_40 AC 16 ms
11,356 KB
testcase_41 AC 42 ms
13,160 KB
testcase_42 AC 28 ms
12,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

//defmodfact
const int COMinitMAX = 998244;
mint fact[COMinitMAX+1], factinv[COMinitMAX+1];

void modfact(){
	fact[0] = 1;
	for (int i=1; i<=COMinitMAX; i++){
		fact[i] = fact[i-1] * i;
	}
	factinv[COMinitMAX] = fact[COMinitMAX].inv();
	for (int i=COMinitMAX-1; i>=0; i--){
		factinv[i] = factinv[i+1] * (i+1);
	}
}

mint cmb(int a, int b){
	if (a<b || b<0) return mint(0);
	return fact[a]*factinv[b]*factinv[a-b];
}
//--------


int main(){
	modfact();
	int n, m; cin >> n >> m;
	vector<int> b(n);
	rep(i,0,n) cin >> b[i];
	int a = m-b[0];
	
	vector<vector<mint>> dp(n, vector<mint>(a+1));
	dp[0][0] = 1;
	rep(i,1,n){
		vector<mint> x(a+1);
		vector<mint> y(a+1);
		rep(k,0,a+1){
			if (b[i-1]-k >= 0){
				x[k] = dp[i-1][k] * factinv[k] * fact[b[i-1]-k];
			}
		}
		rep(k,0,a+1){
			if (b[i-1]-b[i]+k >= 0){
				y[k] = factinv[k] * factinv[b[i-1]-b[i]+k];
			}
		}
		vector<mint> z = convolution(x, y);
		rep(j,0,a+1){
			if (b[i]-j >= 0){
				dp[i][j] = fact[j] * factinv[b[i]-j] * z[j];
			}
		}
	}
	mint ans = 0;
	rep(j,0,a+1){
		ans += dp[n-1][j] * cmb(m, b[0] + j) * cmb(b[0] + j, b[0]);
	}
	cout << ans.val() << '\n';
}

0