結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
11,184 KB
testcase_01 AC 15 ms
11,172 KB
testcase_02 AC 15 ms
11,124 KB
testcase_03 AC 14 ms
11,132 KB
testcase_04 AC 15 ms
11,412 KB
testcase_05 AC 15 ms
11,260 KB
testcase_06 AC 15 ms
11,128 KB
testcase_07 AC 15 ms
11,160 KB
testcase_08 AC 14 ms
11,176 KB
testcase_09 AC 15 ms
11,148 KB
testcase_10 AC 15 ms
11,124 KB
testcase_11 AC 15 ms
11,348 KB
testcase_12 AC 18 ms
11,392 KB
testcase_13 AC 15 ms
11,280 KB
testcase_14 AC 15 ms
11,220 KB
testcase_15 AC 14 ms
11,388 KB
testcase_16 AC 15 ms
11,468 KB
testcase_17 AC 15 ms
11,296 KB
testcase_18 AC 17 ms
11,388 KB
testcase_19 AC 15 ms
11,128 KB
testcase_20 AC 15 ms
11,128 KB
testcase_21 AC 15 ms
11,348 KB
testcase_22 AC 16 ms
11,180 KB
testcase_23 AC 15 ms
11,220 KB
testcase_24 AC 15 ms
11,308 KB
testcase_25 AC 62 ms
13,292 KB
testcase_26 AC 44 ms
12,208 KB
testcase_27 AC 18 ms
11,548 KB
testcase_28 AC 29 ms
11,680 KB
testcase_29 AC 44 ms
12,020 KB
testcase_30 AC 61 ms
13,260 KB
testcase_31 AC 107 ms
13,208 KB
testcase_32 AC 108 ms
13,496 KB
testcase_33 AC 108 ms
13,420 KB
testcase_34 AC 62 ms
13,252 KB
testcase_35 AC 62 ms
13,316 KB
testcase_36 AC 63 ms
13,120 KB
testcase_37 AC 109 ms
13,264 KB
testcase_38 AC 62 ms
13,304 KB
testcase_39 AC 62 ms
13,172 KB
testcase_40 AC 108 ms
13,344 KB
testcase_41 AC 62 ms
13,220 KB
testcase_42 AC 15 ms
11,168 KB
testcase_43 AC 13 ms
11,120 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