제출 #869644

#제출 시각아이디문제언어결과실행 시간메모리
869644sleepntsheepSkyscraper (JOI16_skyscraper)C++17
100 / 100
153 ms5212 KiB
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;

#define int long long
const ll M = 1'000'000'007;
int I, n, l, a[101], dp[2][101][1001][3], z, D;

inline int O(int j, int k, int l)
{
    k -= (2*j-l) * D;
    if (j < 0 || k < 0) return 0;
    return dp[!I][j][k][l];
}

signed main()
{
    ShinLena;
    cin >> n >> l;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a+1, a+n+1);
    dp[1][1][0][0] = 1;
    dp[1][1][0][1] = 2;
    for (int i = 2; i <= n; ++i, I ^= 1)
    {
        D = a[i] - a[i-1];
        memset(dp[I], 0, sizeof *dp);
        for (int j = 1; j <= i; ++j)
        {
            for (int k = 1; k <= l; ++k)
            {
                /* dp[I][j][k][0] */ {
                    int &d = dp[I][j][k][0];
                    (d += O(j+1, k, 0) * j % M) %= M;

                    (d += O(j-1, k, 0) * j % M) %= M;

                    (d += O(j+0, k, 0) * 2*j % M) %= M;
                }

                /* dp[I][j][k][1] */ {
                    int &d = dp[I][j][k][1];
                    (d += O(j+1, k, 1) * j % M) %= M;

                    (d += O(j-1, k, 1) * (j-1) % M) %= M;

                    (d += O(j+0, k, 1) * (2*j-1) % M) %= M;

                    (d += O(j-1, k, 0) * 2 % M) %= M;

                    (d += O(j+0, k, 0) * 2 % M) %= M;
                }

                /* dp[I][j][k][2] */ {

                    int &d = dp[I][j][k][2];
                    (d += O(j+1, k, 2) * j % M) %= M;

                    (d += O(j-1, k, 2) * (j-2) % M) %= M;

                    (d += O(j+0, k, 2) * (2*j-2) % M) %= M;

                    (d += O(j-1, k, 1) % M) %= M;

                    (d += O(j+0, k, 1) % M) %= M;
                }
            }
        }
    }

    for (int k = 0; k <= l; ++k) (z += dp[n&1][1][k][2] % M) %= M;
    cout << z + (n == 1);

    return 0;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...