답안 #873710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873710 2023-11-15T13:52:47 Z Pannda Skyscraper (JOI16_skyscraper) C++17
100 / 100
133 ms 5244 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int P = (int)1e9 + 7;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    if (n == 1) {
        cout << 1 << '\n';
        return 0;
    }

    // (comp, cnt, sum): 'comp' components, 'cnt' bounding elements, total delta of 'sum' | after adding a[i]
    vector<vector<vector<int>>> prev(n + 1, vector<vector<int>>(3, vector<int>(l + 1, 0)));
    prev[1][0][0] = 1;
    prev[1][1][0] = 2;

    for (int i = 1; i < n; i++) {
        vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(3, vector<int>(l + 1, 0)));
        int d = a[i] - a[i - 1];
        for (int comp = 0; comp <= n; comp++) {
            for (int sum = 0; sum <= l; sum++) {
                // 0 bounding element
                if (sum + (2 * comp) * d <= l) {
                    if (comp + 1 <= n) (dp[comp + 1][0][sum + (2 * comp) * d] += (comp + 1) * prev[comp][0][sum]) %= P;
                    (dp[comp][0][sum + (2 * comp) * d] += (2 * comp) * prev[comp][0][sum]) %= P;
                    if (comp - 1 >= 0) (dp[comp - 1][0][sum + (2 * comp) * d] += (comp - 1) * prev[comp][0][sum]) %= P;
                }

                // 1 bounding element
                if (0 <= sum + (2 * comp - 1) * d && sum + (2 * comp - 1) * d <= l) {
                    if (comp + 1 <= n) (dp[comp + 1][1][sum + (2 * comp - 1) * d] += (comp) * prev[comp][1][sum]) %= P;
                    (dp[comp][1][sum + (2 * comp - 1) * d] += (2 * comp - 1) * prev[comp][1][sum]) %= P;
                    if (comp - 1 >= 0) (dp[comp - 1][1][sum + (2 * comp - 1) * d] += (comp - 1) * prev[comp][1][sum]) %= P;
                }
                if (sum + (2 * comp) * d <= l) {
                    if (comp + 1 <= n) (dp[comp + 1][1][sum + (2 * comp) * d] += 2 * prev[comp][0][sum]) %= P;
                    (dp[comp][1][sum + (2 * comp) * d] += 2 * prev[comp][0][sum]) %= P;
                }

                // 2 bounding elements
                if (0 <= sum + (2 * comp - 2) * d && sum + (2 * comp - 2) * d <= l) {
                    if (comp + 1 <= n) (dp[comp + 1][2][sum + (2 * comp - 2) * d] += (comp - 1) * prev[comp][2][sum]) %= P;
                    (dp[comp][2][sum + (2 * comp - 2) * d] += (2 * comp - 2) * prev[comp][2][sum]) %= P;
                    if (comp - 1 >= 0) (dp[comp - 1][2][sum + (2 * comp - 2) * d] += (comp - 1) * prev[comp][2][sum]) %= P;
                }
                if (0 <= sum + (2 * comp - 1) * d && sum + (2 * comp - 1) * d <= l) {
                    if (comp + 1 <= n) (dp[comp + 1][2][sum + (2 * comp - 1) * d] += prev[comp][1][sum]) %= P;
                    (dp[comp][2][sum + (2 * comp - 1) * d] += prev[comp][1][sum]) %= P;
                }
            }
        }
        swap(dp, prev);
    }

    cout << accumulate(prev[1][2].begin(), prev[1][2].end(), 0LL) % P << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 119 ms 3420 KB Output is correct
23 Correct 133 ms 4956 KB Output is correct
24 Correct 112 ms 3932 KB Output is correct
25 Correct 132 ms 5220 KB Output is correct
26 Correct 118 ms 4508 KB Output is correct
27 Correct 49 ms 1628 KB Output is correct
28 Correct 71 ms 1884 KB Output is correct
29 Correct 104 ms 3360 KB Output is correct
30 Correct 132 ms 5244 KB Output is correct