Submission #1339753

#TimeUsernameProblemLanguageResultExecution timeMemory
1339753iamhereforfunSkyscraper (JOI16_skyscraper)C++20
20 / 100
2107 ms296100 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 = 1e5 + 5 + 2e3;
const int O = 1e5 + 5;
const int LG = 20;
const int INF = 1e9 + 5;
const int B = 1000;
const int MOD = 1e9 + 7;

int n, l, a[N], del;
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];
    }
    if (n == 1)
    {
        cout << 1 << "\n";
        return;
    }
    sort(a + 1, a + n + 1);
    dp1[0][O][0] = 1;
    for (int x = 1; x <= n; x++)
    {
        del += 2 * a[x];
        for (int y = 1; y <= x; y++)
        {
            for (int z = max(0, M - (int)2e3 - 5 - del); z < M; z++)
            {
                // add without interfering with the edges
                if ((n - x + 1) - 2 + 0 > 0)
                    dp2[y][z][0] += (2 * y - 0) * dp1[y][z][0];
                if (z - 2 * a[x] >= 0)
                    dp2[y][z][0] += y * dp1[y + 1][z - 2 * a[x]][0];
                if (z + 2 * a[x] < M)
                    dp2[y][z][0] += (y - 0) * dp1[y - 1][z + 2 * a[x]][0];
                dp2[y][z][0] %= MOD;
                // add without interfering with the edges
                if ((n - x + 1) - 2 + 1 > 0)
                    dp2[y][z][1] += (2 * y - 1) * dp1[y][z][1];
                if (z - 2 * a[x] >= 0)
                    dp2[y][z][1] += y * dp1[y + 1][z - 2 * a[x]][1];
                if (z + 2 * a[x] < M)
                    dp2[y][z][1] += (y - 1) * dp1[y - 1][z + 2 * a[x]][1];
                dp2[y][z][1] %= MOD;
                // add without interfering with the edges
                if ((n - x + 1) - 2 + 2 > 0)
                    dp2[y][z][2] += (2 * y - 2) * dp1[y][z][2];
                if (z - 2 * a[x] >= 0)
                    dp2[y][z][2] += y * dp1[y + 1][z - 2 * a[x]][2];
                if (z + 2 * a[x] < M)
                    dp2[y][z][2] += (y - 2) * dp1[y - 1][z + 2 * a[x]][2];
                dp2[y][z][2] %= MOD;
                // interfering with the edges
                if (z + a[x] < M)
                    dp2[y][z][2] += dp1[y - 1][z + a[x]][2 - 1];
                if (z - a[x] >= 0)
                    dp2[y][z][2] += dp1[y][z - a[x]][2 - 1];
                dp2[y][z][2] %= MOD;
                if (z + a[x] < M)
                    dp2[y][z][1] += 2 * dp1[y - 1][z + a[x]][1 - 1];
                if (z - a[x] >= 0)
                    dp2[y][z][1] += 2 * dp1[y][z - a[x]][1 - 1];
                dp2[y][z][1] %= MOD;
            }
        }
        for (int y = 0; y <= x; y++)
        {
            for (int z = max(0, M - (int)2e3 - 5 - del); z < M; z++)
            {
                dp1[y][z][0] = dp2[y][z][0];
                dp2[y][z][0] = 0;
                dp1[y][z][1] = dp2[y][z][1];
                dp2[y][z][1] = 0;
                dp1[y][z][2] = dp2[y][z][2];
                dp2[y][z][2] = 0;
            }
        }
    }
    ans = 0;
    for (int x = 0; x <= l; x++)
    {
        ans += dp1[1][O + x][2];
        // cout << dp1[1][O + x][2] << "\n";
    }
    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...