답안 #1069188

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069188 2024-08-21T17:12:42 Z Sharky Skyscraper (JOI16_skyscraper) C++17
15 / 100
1 ms 860 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mod = 1'000'000'007;
const int N = 108, L = 1008;

int dp[N][N][L][3], a[N];

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, l;
    cin >> n >> l;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (n == 1) {
        cout << !!(a[1] <= l) << '\n';
        return 0;
    }
    sort(a + 1, a + n + 1);
    dp[0][0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k <= l; k++) {
                for (int m = 0; m <= 2; m++) {
                    int v = dp[i - 1][j][k][m];
                    if (!v) continue;
                    // cout << i - 1 << " " << j << " " << k << " " << m << " " << v << "\n";
                    int add = (2 * j - m) * (a[i] - a[i - 1]);
                    if (k + add > l) continue;
                    if (j > 1) (dp[i][j - 1][k + add][m] += (v * (j - 1)) % mod) %= mod;
                    if (j) (dp[i][j][k + add][m] += (v * (2 * j - m)) % mod) %= mod;
                    (dp[i][j + 1][k + add][m] += (v * (j + 1 - m)) % mod) %= mod;
                    if (m < 2) {
                        (dp[i][j + 1][k + add][m + 1] += (v * (2 - m)) % mod) %= mod;
                        if (j) (dp[i][j][k + add][m + 1] += (v * (2 - m)) % mod) %= mod;
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= l; i++) (ans += dp[n][1][i][2]) %= mod;
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -