# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
903425 | duckindog | Magneti (COCI21_magneti) | C++14 | 242 ms | 52888 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
const int N = 50 + 10,
L = 1e4 + 10,
M = 1e9 + 7;
int n, l;
int a[N];
int f[N][N][L];
const int F = 1e5 + 10;
int fac[F], ifac[F];
int powder(int a, int b) {
int ret = 1;
while (b) {
if (b & 1) ret = 1ll * ret * a % M;
a = 1ll * a * a % M;
b /= 2;
}
return ret;
}
int C(int n, int k) {
if (n < k) return 0;
return 1ll * fac[n] * ifac[k] % M * ifac[n - k] % M;
}
void init() {
int x = 1e5;
fac[1] = 1;
for (int i = 2; i <= x; ++i) fac[i] = 1ll * fac[i - 1] * i % M;
ifac[x] = powder(fac[x], M - 2);
for (int i = x; i >= 1; --i) ifac[i - 1] = 1ll * ifac[i] * i % M;
}
void add(int &x, long long y) {
x = ((x + y) % M + M) % M;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
init();
cin >> n >> l;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + n + 1);
f[0][0][0] = 1;
int x = 4, y = 2, z = 4;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
for (int t = 1; t <= l; ++t) {
auto &ret = f[i][j][t];
int r = a[i];
//create
add(ret, 1ll * f[i - 1][j - 1][t - 1]);
//add
if (r <= t) add(ret, 1ll * f[i - 1][j][t - r] * 2 * j % M);
//connect
if (2 * r - 1 <= t)
add(ret, 1ll * f[i - 1][j + 1][t - 2 * r + 1] * j * (j + 1) % M);
}
}
}
int answer = 0;
for (int i = 1; i <= l; ++i) add(answer, 1ll * f[n][1][i] * C(n + l - i, n) % M);
cout << answer << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |