結果

問題 No.1474 かさまJ
ユーザー 沙耶花沙耶花
提出日時 2021-04-09 22:00:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 269 ms / 2,500 ms
コード長 1,568 bytes
コンパイル時間 4,583 ms
コンパイル使用メモリ 267,188 KB
実行使用メモリ 14,800 KB
最終ジャッジ日時 2023-09-07 11:15:24
合計ジャッジ時間 7,337 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
11,488 KB
testcase_01 AC 20 ms
11,592 KB
testcase_02 AC 22 ms
11,472 KB
testcase_03 AC 21 ms
11,520 KB
testcase_04 AC 21 ms
11,520 KB
testcase_05 AC 126 ms
13,496 KB
testcase_06 AC 39 ms
11,828 KB
testcase_07 AC 21 ms
11,528 KB
testcase_08 AC 21 ms
11,456 KB
testcase_09 AC 168 ms
13,580 KB
testcase_10 AC 27 ms
11,808 KB
testcase_11 AC 21 ms
11,792 KB
testcase_12 AC 20 ms
11,520 KB
testcase_13 AC 175 ms
13,824 KB
testcase_14 AC 65 ms
12,124 KB
testcase_15 AC 38 ms
11,852 KB
testcase_16 AC 25 ms
12,064 KB
testcase_17 AC 74 ms
12,956 KB
testcase_18 AC 223 ms
14,484 KB
testcase_19 AC 254 ms
14,580 KB
testcase_20 AC 269 ms
14,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

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);
	}
	
};

int main(){
	
	int N,Mp,Mq,L;
	cin>>N>>Mp>>Mq>>L;
	
	vector<int> S(N);
	rep(i,N){
		cin>>S[i];
	}
	
	vector dp(N+1,vector<mint>(Mq+1,0));
	dp[0][0] = 1;
	
	rep(i,N){
		
		rep(j,N+1){
			rep(k,Mq){
				dp[j][k+1] += dp[j][k];
			}
		}
		
		vector ndp(N+1,vector<mint>(Mq+1,0));
		rep(j,N+1){
			rep(k,Mq+1){
				ndp[j][k] += dp[j][k];
				if(k!=0)ndp[j][k] -= dp[j][k-1];
				
				if(j!=0 && k!=0){
					ndp[j][k] += dp[j-1][k-1];
					if(k-1-S[i]>=0){
						ndp[j][k] -= dp[j-1][k-1-S[i]];
					}
				}
				
			}
		}
		swap(dp,ndp);
		
	}
	
	combi C(1000000);
	mint ans = 0;
	rep(i,N+1){
		mint t = 0;
		rep(j,Mq+1){
			t = dp[i][j];
			if(Mp-L*i+j>=0){
				t *= C.junretsu(N-1,Mp-L*i+j);
				ans += t;
			}
		}
	}
	
	cout<<ans.val()<<endl;
	
    return 0;
}
0