結果
| 問題 |
No.1474 かさまJ
|
| コンテスト | |
| ユーザー |
cookiedoth
|
| 提出日時 | 2021-04-09 23:03:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 291 ms / 2,500 ms |
| コード長 | 3,601 bytes |
| コンパイル時間 | 2,007 ms |
| コンパイル使用メモリ | 131,532 KB |
| 最終ジャッジ日時 | 2025-01-20 15:06:31 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
ソースコード
/*
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();
}
cookiedoth