結果

問題 No.1474 かさまJ
ユーザー cookiedothcookiedoth
提出日時 2021-04-09 23:03:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 176 ms / 2,500 ms
コード長 3,601 bytes
コンパイル時間 1,424 ms
コンパイル使用メモリ 135,692 KB
実行使用メモリ 11,108 KB
最終ジャッジ日時 2023-09-07 12:45:50
合計ジャッジ時間 3,766 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,792 KB
testcase_01 AC 27 ms
10,800 KB
testcase_02 AC 30 ms
10,824 KB
testcase_03 AC 27 ms
10,792 KB
testcase_04 AC 27 ms
10,968 KB
testcase_05 AC 85 ms
11,108 KB
testcase_06 AC 43 ms
10,808 KB
testcase_07 AC 32 ms
10,856 KB
testcase_08 AC 34 ms
10,804 KB
testcase_09 AC 117 ms
10,796 KB
testcase_10 AC 31 ms
10,864 KB
testcase_11 AC 25 ms
10,792 KB
testcase_12 AC 27 ms
10,820 KB
testcase_13 AC 121 ms
10,836 KB
testcase_14 AC 62 ms
10,876 KB
testcase_15 AC 47 ms
10,996 KB
testcase_16 AC 30 ms
10,820 KB
testcase_17 AC 59 ms
10,800 KB
testcase_18 AC 152 ms
10,796 KB
testcase_19 AC 168 ms
10,792 KB
testcase_20 AC 176 ms
10,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*

Code for problem F by cookiedoth
Generated 09 Apr 2021 at 04.37 PM


▅███████ ]▄▄▄▄▄▄▄ 
█████████▅▄▃ 
Il████████████████] 
◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤

>_<
o_O
^_^

*/

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#include <random>
#include <utility>
#include <tuple>
#include <chrono>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) cerr << #a << " = " << a << endl
#define forn(i, n) for (int i = 0; i < n; ++i)
#define length(a) (int)a.size()

using namespace std;

template<class T> int chkmax(T &a, T b) {
	if (b > a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class T> int chkmin(T &a, T b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) {
	while (begin != end) {
		out << (*begin) << " ";
		begin++;
	}
	out << endl;
}

template<class T> void output(T x, ostream& out = cerr) {
	output(x.begin(), x.end(), out);
}

void fast_io() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

const int MOD = 1e9 + 7;

int mul(int a, int b) {
	return (1LL * a * b) % MOD;
}

int diff(int a, int b) {
	a -= b;
	if (a < 0) {
		a += MOD;
	}
	return a;
}

void subt(int &a, const int &b) {
	a -= b;
	if (a < 0) {
		a += MOD;
	}
}

int sum(int a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
	return a;
}

void add(int &a, const int &b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int power(int a, int deg) {
	int res = 1;
	for (; deg; a = mul(a, a), deg >>= 1) {
		if (deg & 1) {
			res = mul(res, a);
		}
	}
	return res;
}

int inverse(int a) {
	return power(a, MOD - 2);
}

int divide(int a, int b) {
	return mul(a, inverse(b));
}

const int MAX_N = 42;
const int C = 2e4 + 228;
int n, M_p, M_q, L;
int dp[MAX_N][C], _dp[MAX_N][C];

void recalcDP(int s) {
	for (int i = 0; i <= n; ++i) {
		copy(dp[i], dp[i] + M_q + 1, _dp[i]);
		for (int j = 1; j <= M_q; ++j) {
			add(dp[i][j], dp[i][j - 1]);
		}
		if (i) {
			for (int j = 1; j <= M_q; ++j) {
				int ps = j - 1 - s;
				add(_dp[i][j], dp[i - 1][j - 1]);
				if (ps >= 0) {
					subt(_dp[i][j], dp[i - 1][ps]);
				}
			}
		}
	}
	swap(dp, _dp);
}

const int mx = 1e5;
int fact[mx], _fact[mx];

void init_binom() {
	fact[0] = _fact[0] = 1;
	for (int i = 1; i < mx; ++i) {
		fact[i] = mul(fact[i - 1], i);
		_fact[i] = inverse(fact[i]);
	}
}

int binom(int n, int k) {
	return k > n ? 0 : mul(fact[n], mul(_fact[k], _fact[n - k]));
}

void calc_ans() {
	int ans = 0;
	for (int q1 = 0; q1 <= n; ++q1) {
		for (int cov = 0; cov <= M_q; ++cov) {
			int remP = M_p - (L * q1 - cov);
			if (remP < 0 || dp[q1][cov] == 0) {
				continue;
			}
			// cerr << "q1 = " << q1 << ", cov = " << cov << '\n';
			// cerr << "opa " << remP << ' ' << dp[q1][cov] << '\n';
			add(ans, mul(binom(remP + n - 1, n - 1), dp[q1][cov]));
			// cerr << "ans = " << ans << '\n';
		}
	}
	cout << ans << '\n';
}

signed main() {
	fast_io();
	cin >> n >> M_p >> M_q >> L;
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i) {
		int s;
		cin >> s;
		recalcDP(s);
	}
	init_binom();
	calc_ans();
}
0