結果

問題 No.1474 かさまJ
ユーザー kwm_tkwm_t
提出日時 2021-04-11 17:39:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 269 ms / 2,500 ms
コード長 1,990 bytes
コンパイル時間 3,684 ms
コンパイル使用メモリ 231,064 KB
実行使用メモリ 141,764 KB
最終ジャッジ日時 2023-09-09 19:49:27
合計ジャッジ時間 7,300 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
141,584 KB
testcase_01 AC 65 ms
141,760 KB
testcase_02 AC 65 ms
141,656 KB
testcase_03 AC 74 ms
141,624 KB
testcase_04 AC 63 ms
141,764 KB
testcase_05 AC 155 ms
141,636 KB
testcase_06 AC 80 ms
141,528 KB
testcase_07 AC 62 ms
141,700 KB
testcase_08 AC 77 ms
141,428 KB
testcase_09 AC 175 ms
141,564 KB
testcase_10 AC 44 ms
141,620 KB
testcase_11 AC 39 ms
141,568 KB
testcase_12 AC 39 ms
141,588 KB
testcase_13 AC 188 ms
141,440 KB
testcase_14 AC 82 ms
141,572 KB
testcase_15 AC 58 ms
141,756 KB
testcase_16 AC 43 ms
141,440 KB
testcase_17 AC 87 ms
141,692 KB
testcase_18 AC 226 ms
141,548 KB
testcase_19 AC 258 ms
141,468 KB
testcase_20 AC 269 ms
141,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include "atcoder/all"
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		return com(n, k);
	}
	mint com(int n, int k) {
		//if (n < 0) return com(-n, k) * (k % 2 ? -1 : 1);
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
	mint inv(int n, int k) {
		//if (n < 0) return inv(-n, k) * (k % 2 ? -1 : 1);
		if (k < 0 || k > n) return 0;
		return ifact[n] * fact[k] * fact[n - k];
	}
}c(100000);
mint dp[42][42][20005];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, mp, mq, l;
	cin >> n >> mp >> mq >> l;
	vector<int>s(n);
	rep(i, n) { cin >> s[i]; }
	/*
		ΣΣf(m,n) * c((mp + m - nl + n - 1),n - 1)
	*/
	//前計算
	dp[0][0][0] = 1;
	rep(i, n) {
		rep(j, n + 1) {
			rep(k, mq + 1) {
				dp[i + 1][j][k] += dp[i][j][k];
				dp[i + 1][j][k + 1] -= dp[i][j][k];
				dp[i + 1][j + 1][k + 1] += dp[i][j][k];
				dp[i + 1][j + 1][min(mq + 1, k + s[i] + 1)] -= dp[i][j][k];
			}
		}
		//累積和
		rep(j, n + 1) {
			rep(k, mq + 1) {
				dp[i + 1][j][k + 1] += dp[i + 1][j][k];
			}
		}
	}
	mint ans = 0;
	rep(i, mq + 1) {
		rep(j, n + 1) {
			ans += dp[n][j][i] * c(mp + i - j * l + n - 1, n - 1);
		}
	}
	cout << ans.val() << endl;
	return 0;
}
0