제출 #678325

#제출 시각아이디문제언어결과실행 시간메모리
678325stevancvSkyscraper (JOI16_skyscraper)C++14
20 / 100
155 ms5160 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sadd(a, b) a = Add(a, b)
#define smul(a, b) a = Mul(a, b)
using namespace std;
const int N = 100 + 2;
const int M = 1000 + 2;
const int mod = 1e9 + 7;
int Add(int a, int b) {
    a += b;
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}
int Mul(int a, int b) {
    ll c = a; c *= b; c %= mod;
    return c;
}
int dp[N][M][3], odp[N][M][3], a[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, l;
    cin >> n >> l;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (n == 1) {
        cout << 1 << en;
        return 0;
    }
    sort(a + 1, a + n + 1);
    if (a[2] - a[1] <= l) dp[1][a[2] - a[1]][1] = 2;
    if (2 * (a[2] - a[1]) <= l) dp[1][2 * (a[2] - a[1])][0] = 1;
    for (int i = 2; i <= n; i++) {
        int diff = a[i + 1] - a[i];
        for (int j = 1; j <= i; j++) {
            for (int s = 0; s <= l; s++) {
                for (int e = 0; e < 3; e++) {
                    odp[j][s][e] = dp[j][s][e];
                    dp[j][s][e] = 0;
                }
            }
        }
        for (int j = 1; j <= i; j++) {
            for (int s = 0; s <= l; s++) {
                for (int e = 0; e < 3; e++) {
                    int kol = 2 * j - e;
                    if (s < diff * kol) continue;
                    sadd(dp[j][s][e], Mul(j - e, odp[j - 1][s - diff * kol][e]));
                    sadd(dp[j][s][e], Mul(2 * j - e, odp[j][s - diff * kol][e]));
                    sadd(dp[j][s][e], Mul(j, odp[j + 1][s - diff * kol][e]));
                    if (e == 0) continue;
                    sadd(dp[j][s][e], Mul(3 - e, odp[j - 1][s - diff * kol][e - 1]));
                    sadd(dp[j][s][e], Mul(3 - e, odp[j][s - diff * kol][e - 1]));
                }
            }
        }
    }
    int ans = 0;
    for (int s = 0; s <= l; s++) sadd(ans, dp[1][s][2]);
    cout << ans << en;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...