Submission #529631

# Submission time Handle Problem Language Result Execution time Memory
529631 2022-02-23T09:31:07 Z Vimmer Magneti (COCI21_magneti) C++14
110 / 110
115 ms 5012 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")

#define F first
#define S second
#define PB push_back
#define M ll(1e9 + 7)
#define sz(x) (ll)x.size()
#define N 100005
#define pri(x) cout << x << endl
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

using namespace std;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;


int mlt(int x, int y)
{
    return 1ll * x * y % M;
}

int sm(int x, int y)
{
    x += y;

    if (x >= M)
        x -= M;

    return x;
}

int fact[N];

int binpow(int a, int b)
{
    if (b == 0)
        return 1;

    int s = binpow(a, b >> 1);

    s = mlt(s, s);

    if (b & 1)
        s = mlt(s, a);

    return s;
}

int C(int n, int k)
{
    return mlt(fact[n], binpow(mlt(fact[k], fact[n - k]), M - 2));
}

int ans, n, l;

int dp[55][10500];
int lst[55][10500];

int main()
{
    istream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//    freopen("1.in", "r", stdin);

    fact[0] = 1;

    for (int i = 1; i < N; i++)
        fact[i] = mlt(fact[i - 1], i);

    cin >> n >> l;

    vector <int> r(n);

    for (int i = 0; i < n; i++)
        cin >> r[i];

    sort(all(r));

    lst[0][0] = 1;

    for (int i = 0; i < n; i++)
    {
        memset(dp, 0, sizeof dp);

        for (int j = 1; j <= i + 1; j++)
            for (int k = 1; k <= l; k++)
            {
                dp[j][k] = lst[j - 1][k - 1];

                if (k >= r[i])
                    dp[j][k] = sm(dp[j][k], mlt(j + j, lst[j][k - r[i]]));

                if (k + 1 >= r[i] + r[i])
                    dp[j][k] = sm(dp[j][k], mlt(j * (j + 1), lst[j + 1][k - r[i] - r[i] + 1]));
            }

        lst[0][0] = 0;

        for (int j = 1; j <= i + 1; j++)
            for (int k = 1; k <= l; k++)
                {
                    lst[j][k] = dp[j][k];
                }
    }

    for (int u = 1; u <= l; u++)
        ans = sm(ans, mlt(C(n + l - u, n), lst[1][u]));

    pri(ans);
}
# Verdict Execution time Memory Grader output
1 Correct 107 ms 4892 KB Output is correct
2 Correct 5 ms 3148 KB Output is correct
3 Correct 15 ms 3280 KB Output is correct
4 Correct 5 ms 3012 KB Output is correct
5 Correct 9 ms 3260 KB Output is correct
6 Correct 35 ms 4036 KB Output is correct
7 Correct 26 ms 4164 KB Output is correct
8 Correct 3 ms 2884 KB Output is correct
9 Correct 11 ms 3768 KB Output is correct
10 Correct 3 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3384 KB Output is correct
2 Correct 3 ms 3020 KB Output is correct
3 Correct 9 ms 3276 KB Output is correct
4 Correct 5 ms 3116 KB Output is correct
5 Correct 9 ms 3384 KB Output is correct
6 Correct 4 ms 3020 KB Output is correct
7 Correct 9 ms 3348 KB Output is correct
8 Correct 3 ms 3020 KB Output is correct
9 Correct 4 ms 3020 KB Output is correct
10 Correct 3 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3096 KB Output is correct
2 Correct 3 ms 3012 KB Output is correct
3 Correct 5 ms 3020 KB Output is correct
4 Correct 4 ms 3020 KB Output is correct
5 Correct 5 ms 3020 KB Output is correct
6 Correct 4 ms 3020 KB Output is correct
7 Correct 4 ms 3016 KB Output is correct
8 Correct 2 ms 3020 KB Output is correct
9 Correct 4 ms 3020 KB Output is correct
10 Correct 2 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 4892 KB Output is correct
2 Correct 5 ms 3148 KB Output is correct
3 Correct 15 ms 3280 KB Output is correct
4 Correct 5 ms 3012 KB Output is correct
5 Correct 9 ms 3260 KB Output is correct
6 Correct 35 ms 4036 KB Output is correct
7 Correct 26 ms 4164 KB Output is correct
8 Correct 3 ms 2884 KB Output is correct
9 Correct 11 ms 3768 KB Output is correct
10 Correct 3 ms 2892 KB Output is correct
11 Correct 9 ms 3384 KB Output is correct
12 Correct 3 ms 3020 KB Output is correct
13 Correct 9 ms 3276 KB Output is correct
14 Correct 5 ms 3116 KB Output is correct
15 Correct 9 ms 3384 KB Output is correct
16 Correct 4 ms 3020 KB Output is correct
17 Correct 9 ms 3348 KB Output is correct
18 Correct 3 ms 3020 KB Output is correct
19 Correct 4 ms 3020 KB Output is correct
20 Correct 3 ms 2892 KB Output is correct
21 Correct 5 ms 3096 KB Output is correct
22 Correct 3 ms 3012 KB Output is correct
23 Correct 5 ms 3020 KB Output is correct
24 Correct 4 ms 3020 KB Output is correct
25 Correct 5 ms 3020 KB Output is correct
26 Correct 4 ms 3020 KB Output is correct
27 Correct 4 ms 3016 KB Output is correct
28 Correct 2 ms 3020 KB Output is correct
29 Correct 4 ms 3020 KB Output is correct
30 Correct 2 ms 3020 KB Output is correct
31 Correct 105 ms 4920 KB Output is correct
32 Correct 68 ms 4376 KB Output is correct
33 Correct 107 ms 4948 KB Output is correct
34 Correct 25 ms 3780 KB Output is correct
35 Correct 106 ms 5008 KB Output is correct
36 Correct 10 ms 3404 KB Output is correct
37 Correct 114 ms 4920 KB Output is correct
38 Correct 21 ms 3404 KB Output is correct
39 Correct 104 ms 4980 KB Output is correct
40 Correct 35 ms 3960 KB Output is correct
41 Correct 103 ms 4916 KB Output is correct
42 Correct 3 ms 3020 KB Output is correct
43 Correct 115 ms 5012 KB Output is correct
44 Correct 13 ms 3532 KB Output is correct
45 Correct 106 ms 4980 KB Output is correct
46 Correct 5 ms 3020 KB Output is correct
47 Correct 16 ms 3916 KB Output is correct
48 Correct 9 ms 3404 KB Output is correct
49 Correct 6 ms 3160 KB Output is correct
50 Correct 2 ms 3012 KB Output is correct