Submission #1339727

#TimeUsernameProblemLanguageResultExecution timeMemory
1339727iamhereforfunSkyscraper (JOI16_skyscraper)C++20
15 / 100
65 ms15912 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 1e2 + 5;
const int M = 2e4 + 2e3 + 5;
const int O = 2e4 + 5;
const int LG = 20;
const int INF = 1e9 + 5;
const int B = 1000;
const int MOD = 1e9 + 7;

int n, l, a[N];
long long dp1[N][M][3], dp2[N][M][3], ans;

inline void solve()
{
    cin >> n >> l;
    for (int x = 1; x <= n; x++)
    {
        cin >> a[x];
    }
    sort(a + 1, a + n + 1);
    dp1[0][O][0] = 1;
    for (int x = 1; x <= n; x++)
    {
        for (int y = 1; y <= x; y++)
        {
            for (int z = 0; z < M; z++)
            {
                for (int t = 0; t < 3; t++) // add without interfering with the edges
                {
                    if ((n - x + 1) - 2 + t > 0)
                        dp2[y][z][t] += (2 * y - t) * dp1[y][z][t];
                    if (z - 2 * a[x] >= 0)
                        dp2[y][z][t] += y * dp1[y + 1][z - 2 * a[x]][t];
                    if (z + 2 * a[x] < M)
                        dp2[y][z][t] += (y - t) * dp1[y - 1][z + 2 * a[x]][t];
                    dp2[y][z][t] %= MOD;
                }
                for (int t = 1; t < 3; t++)
                {
                    if (t == 2)
                    {
                        if (z + a[x] < M)
                            dp2[y][z][t] += dp1[y - 1][z + a[x]][t - 1];
                        if (z - a[x] >= 0)
                            dp2[y][z][t] += dp1[y][z - a[x]][t - 1];
                        dp2[y][z][t] %= MOD;
                    }
                    else
                    {
                        if (z + a[x] < M)
                            dp2[y][z][t] += 2 * dp1[y - 1][z + a[x]][t - 1];
                        if (z - a[x] >= 0)
                            dp2[y][z][t] += 2 * dp1[y][z - a[x]][t - 1];
                        dp2[y][z][t] %= MOD;
                    }
                }
            }
        }
        for (int y = 0; y <= x; y++)
        {
            for (int z = 0; z < M; z++)
            {
                for (int t = 0; t < 3; t++) // add without interfering with the edges
                {
                    // if (dp2[y][z][t])
                        // cout << y << " " << z - O << " " << t << "\n";
                    dp1[y][z][t] = dp2[y][z][t];
                    dp2[y][z][t] = 0;
                }
            }
        }
    }
    ans = 0;
    for (int x = 0; x <= l; x++)
    {
        ans += dp1[1][O + x][2];
    }
    ans %= MOD;
    cout << ans << "\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...