Submission #1109887

# Submission time Handle Problem Language Result Execution time Memory
1109887 2024-11-08T02:40:36 Z vjudge1 Magneti (COCI21_magneti) C++14
110 / 110
33 ms 12872 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MAXN = 55, MAXL = 1e4 + 505, Mod = 1e9 + 7;
inline void UP(int &x, ll y) {x = (y + x) % Mod;}

int n, l, w[MAXN];
int ans;

int f[MAXN][MAXN][MAXL];

int fac[MAXL], ifc[MAXL], inv[MAXL];
void Fac() {
    fac[0] = ifc[0] = fac[1] = ifc[1] = inv[1] = 1;
    for (int i = 2; i < MAXL; ++i) {
        fac[i] = 1LL * fac[i - 1] * i % Mod;
        inv[i] = -1LL * inv[Mod % i] * (Mod / i) % Mod;
        ifc[i] = 1LL * ifc[i - 1] * inv[i] % Mod;
    }
    return ;
}
inline int C(int n, int m) {
    if (n < 0 || m < 0 || m > n) return 0;
    return 1LL * fac[n] * ifc[m] % Mod * ifc[n - m] % Mod;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> l;
    for (int i = 1; i <= n; ++i) cin >> w[i];

    Fac();
    sort(w + 1, w + 1 + n);
    f[0][0][0] = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= i; ++j) {
            for (int k = 0; k < l; ++k) {
                int val = f[i][j][k];
                if (!val) continue;
                if (k + w[i + 1] <= l) UP(f[i + 1][j][k + w[i + 1]], 2LL * j * val);
                if (j >= 2 && k + 2 * w[i + 1] - 1 <= l) UP(f[i + 1][j - 1][k + 2 * w[i + 1] - 1], 1LL * (j - 1) * val);
                UP(f[i + 1][j + 1][k + 1], 1LL * (j + 1) * val);
            }
        }
    static int *g = f[n][1];
    for (int i = 0; i <= l; ++i)
        UP(ans, 1LL * g[i] * C(l - i + n, n));

    UP(ans, Mod);
    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 5712 KB Output is correct
2 Correct 4 ms 3576 KB Output is correct
3 Correct 2 ms 848 KB Output is correct
4 Correct 1 ms 624 KB Output is correct
5 Correct 3 ms 1528 KB Output is correct
6 Correct 8 ms 2128 KB Output is correct
7 Correct 13 ms 1104 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 5 ms 848 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 848 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 3 ms 848 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 3 ms 848 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 2 ms 1104 KB Output is correct
8 Correct 2 ms 848 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2384 KB Output is correct
2 Correct 2 ms 1360 KB Output is correct
3 Correct 3 ms 2384 KB Output is correct
4 Correct 2 ms 1616 KB Output is correct
5 Correct 3 ms 2384 KB Output is correct
6 Correct 2 ms 1280 KB Output is correct
7 Correct 3 ms 2640 KB Output is correct
8 Correct 1 ms 848 KB Output is correct
9 Correct 2 ms 848 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 5712 KB Output is correct
2 Correct 4 ms 3576 KB Output is correct
3 Correct 2 ms 848 KB Output is correct
4 Correct 1 ms 624 KB Output is correct
5 Correct 3 ms 1528 KB Output is correct
6 Correct 8 ms 2128 KB Output is correct
7 Correct 13 ms 1104 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 5 ms 848 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 2 ms 848 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 3 ms 848 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 3 ms 848 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 2 ms 1104 KB Output is correct
18 Correct 2 ms 848 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 3 ms 2384 KB Output is correct
22 Correct 2 ms 1360 KB Output is correct
23 Correct 3 ms 2384 KB Output is correct
24 Correct 2 ms 1616 KB Output is correct
25 Correct 3 ms 2384 KB Output is correct
26 Correct 2 ms 1280 KB Output is correct
27 Correct 3 ms 2640 KB Output is correct
28 Correct 1 ms 848 KB Output is correct
29 Correct 2 ms 848 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 27 ms 11344 KB Output is correct
32 Correct 19 ms 8784 KB Output is correct
33 Correct 33 ms 11488 KB Output is correct
34 Correct 7 ms 3152 KB Output is correct
35 Correct 27 ms 11120 KB Output is correct
36 Correct 2 ms 1104 KB Output is correct
37 Correct 30 ms 11828 KB Output is correct
38 Correct 9 ms 6224 KB Output is correct
39 Correct 27 ms 12872 KB Output is correct
40 Correct 8 ms 3152 KB Output is correct
41 Correct 27 ms 11320 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 22 ms 7960 KB Output is correct
44 Correct 5 ms 1872 KB Output is correct
45 Correct 21 ms 8272 KB Output is correct
46 Correct 1 ms 592 KB Output is correct
47 Correct 7 ms 2520 KB Output is correct
48 Correct 7 ms 2640 KB Output is correct
49 Correct 2 ms 592 KB Output is correct
50 Correct 1 ms 592 KB Output is correct