結果

問題 No.2485 Add to Variables (Another)
ユーザー 沙耶花沙耶花
提出日時 2023-09-22 22:33:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 2,079 bytes
コンパイル時間 5,545 ms
コンパイル使用メモリ 278,044 KB
実行使用メモリ 40,544 KB
最終ジャッジ日時 2023-09-22 22:33:57
合計ジャッジ時間 11,375 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
36,872 KB
testcase_01 AC 82 ms
36,880 KB
testcase_02 AC 82 ms
36,968 KB
testcase_03 AC 85 ms
36,892 KB
testcase_04 AC 82 ms
36,836 KB
testcase_05 AC 83 ms
36,720 KB
testcase_06 AC 83 ms
36,832 KB
testcase_07 AC 84 ms
36,884 KB
testcase_08 AC 83 ms
36,868 KB
testcase_09 AC 83 ms
36,888 KB
testcase_10 AC 83 ms
36,708 KB
testcase_11 AC 82 ms
36,900 KB
testcase_12 AC 88 ms
37,020 KB
testcase_13 AC 82 ms
36,704 KB
testcase_14 AC 83 ms
36,880 KB
testcase_15 AC 83 ms
36,848 KB
testcase_16 AC 82 ms
36,892 KB
testcase_17 AC 83 ms
36,880 KB
testcase_18 AC 86 ms
36,836 KB
testcase_19 AC 83 ms
36,832 KB
testcase_20 AC 84 ms
36,756 KB
testcase_21 AC 82 ms
36,992 KB
testcase_22 AC 81 ms
36,772 KB
testcase_23 AC 82 ms
36,768 KB
testcase_24 AC 83 ms
36,876 KB
testcase_25 AC 217 ms
40,252 KB
testcase_26 AC 157 ms
39,056 KB
testcase_27 AC 95 ms
37,224 KB
testcase_28 AC 111 ms
37,624 KB
testcase_29 AC 125 ms
38,728 KB
testcase_30 AC 213 ms
40,208 KB
testcase_31 AC 214 ms
40,516 KB
testcase_32 AC 217 ms
40,360 KB
testcase_33 AC 214 ms
40,544 KB
testcase_34 AC 214 ms
40,228 KB
testcase_35 AC 83 ms
36,968 KB
testcase_36 AC 89 ms
37,092 KB
testcase_37 AC 82 ms
36,888 KB
testcase_38 AC 83 ms
36,744 KB
testcase_39 AC 83 ms
36,880 KB
testcase_40 AC 84 ms
36,832 KB
testcase_41 AC 84 ms
36,772 KB
testcase_42 AC 82 ms
36,828 KB
testcase_43 AC 82 ms
36,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
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(4100000);

int main(){
	
	long long n,m;
	cin>>n>>m;
	int M = m;
	vector<long long> b(n);
	rep(i,n)cin>>b[i];
	vector<long long> a(n);
	vector<long long> pre(n),suf(n);
	long long c = 0;
	rep(i,n-1){
		if(b[i+1]-b[i]>0){
			c += b[i+1]-b[i];
			suf[i+1] += b[i+1]-b[i];
			for(int j=i+1;j<n;j++){
				a[j] += b[i+1]-b[i];
			}
		}
		if(b[i+1]-b[i]<0){
			c += b[i]-b[i+1];
			pre[i] += b[i]-b[i+1];
			rep(j,i+1){
				a[j] += b[i]-b[i+1];
			}
		}
	}
	if(a[0]>b[0]||c>m){
		cout<<0<<endl;
		return 0;
	}
	m -= c;
	long long need = b[0]-a[0];
	
		
	queue<vector<mint>> Q;
	Q.push({1});
	rep(i,n-1){
		vector<mint> t(need+2);
		rep(j,t.size()){
			t[j] = C.kaijou_[pre[i]+j] * C.kaijou_[suf[i+1]+j];
		}
		Q.push(t);
	}
	
	while(Q.size()>1){
		auto x = Q.front();
		Q.pop();
		auto y=  Q.front();
		Q.pop();
		Q.push(convolution(x,y));
	}
	auto t =  Q.front();
	mint ans = 0;
	//cout<<need<<' '<<m<<endl;
	rep(i,t.size()){
		if(need<i)break;
		int nn = need - i;
		mint v  = t[i];
		//cout<<i<<' '<<v.val()<<endl;
		int mm = m - i*2;
		if(mm<nn)continue;
		v *= C.kaijou_[nn] * C.kaijou_[mm-nn];
		//cout<<i<<' '<<v.val()<<endl;
		//cout<<mm<<' '<<nn<<endl;
		ans += v;
	}
	ans *= C.kaijou[M];
	cout<<ans.val()<<endl;
	return 0;
}
0