Submission #109718

# Submission time Handle Problem Language Result Execution time Memory
109718 2019-05-07T17:18:35 Z popovicirobert Skyscraper (JOI16_skyscraper) C++14
100 / 100
159 ms 20368 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

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

inline void mod(int &x) {
    if(x >= MOD) x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

const int MAXN = 105;
const int MAXL = 1005;

int dp[MAXN + 1][MAXN + 1][MAXL + 1][2][2];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, n, L;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> L;

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

    vector <int> arr(n + 1);
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
    }

    sort(arr.begin(), arr.end());

    dp[0][0][0][0][0] = 1;

    for(i = 0; i < n; i++) {
        for(j = 0; j <= i; j++) {
            for(int cst = 0; cst <= L; cst++) {
                for(int l = 0; l < 2; l++) {
                    for(int r = 0; r < 2; r++) {
                        int cur = dp[i][j][cst][l][r];
                        if(cur == 0) {
                            continue;
                        }

                        int new_cst = cst + (2 * j - l - r) * (arr[i + 1] - arr[i]);
                        if(new_cst > L) {
                            continue;
                        }

                        add(dp[i + 1][j + 1][new_cst][l][r], cur);
                        if(l == 0) {
                            add(dp[i + 1][j + 1][new_cst][1][r], cur);
                        }
                        if(r == 0) {
                            add(dp[i + 1][j + 1][new_cst][l][1], cur);
                        }

                        add(dp[i + 1][j][new_cst][l][r], (1LL * cur * (2 * j - l - r)) % MOD);
                        if(i == n - 1) {
                            if(l == 0) {
                                add(dp[i + 1][j][new_cst][1][r], (1LL * cur * j) % MOD);
                            }
                            if(r == 0) {
                                add(dp[i + 1][j][new_cst][l][1], (1LL * cur * j) % MOD);
                            }
                        }
                        else {
                            if(l == 0) {
                                add(dp[i + 1][j][new_cst][1][r], (1LL * cur * (j - r)) % MOD);
                            }
                            if(r == 0) {
                                add(dp[i + 1][j][new_cst][l][1], (1LL * cur * (j - l)) % MOD);
                            }
                        }

                        if(j > 0) {
                            if(i == n - 1) {
                                int coef = max(0, l * (j - l - r)) + max(0, (j - l - r) * r) + max(0, (j - l - r) * (j - l - r - 1)) + l * r;
                                add(dp[i + 1][j - 1][new_cst][l][r], (1LL * cur * coef) % MOD);
                            }
                            else {
                                int coef = max(0, l * (j - l - r)) + max(0, (j - l - r) * r) + max(0, (j - l - r) * (j - l - r - 1));
                                add(dp[i + 1][j - 1][new_cst][l][r], (1LL * cur * coef) % MOD);
                            }
                        }

                    }
                }
            }
        }
    }

    int ans = 0;
    for(i = 0; i <= L; i++) {
        add(ans, dp[n][1][i][1][1]);
    }

    cout << ans;

    //cin.close();
    //cout.close();
    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 764 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 640 KB Output is correct
15 Correct 3 ms 640 KB Output is correct
16 Correct 3 ms 768 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 764 KB Output is correct
19 Correct 3 ms 896 KB Output is correct
20 Correct 3 ms 640 KB Output is correct
21 Correct 4 ms 1536 KB Output is correct
22 Correct 159 ms 20368 KB Output is correct
23 Correct 110 ms 8524 KB Output is correct
24 Correct 100 ms 11744 KB Output is correct
25 Correct 104 ms 9336 KB Output is correct
26 Correct 90 ms 8696 KB Output is correct
27 Correct 69 ms 9720 KB Output is correct
28 Correct 67 ms 11640 KB Output is correct
29 Correct 119 ms 15224 KB Output is correct
30 Correct 117 ms 9472 KB Output is correct