Submission #319685

# Submission time Handle Problem Language Result Execution time Memory
319685 2020-11-06T06:41:57 Z qpwoeirut Skyscraper (JOI16_skyscraper) C++17
20 / 100
205 ms 91132 KB
#include <bits/stdc++.h>

using namespace std;

const int MN = 14;
const int MX = 101;
const int MOD = 1e9 + 7;

int N, L;
int A[MN];

int dp[1 << MN][MN][MX];

void add(int& a, const int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> N >> L;
    for (int i=0; i<N; ++i) {
        cin >> A[i];
    }
    int ans = 0;
    if (N <= 8) {
        sort(A, A+N);

        do {
            int cur = 0;
            for (int i=1; i<N; ++i) {
                cur += abs(A[i] - A[i-1]);
            }
            if (cur <= L) ++ans;
        } while (next_permutation(A, A+N));

        cout << ans << endl;
        return 0;
    }
    for (int i=0; i<N; ++i) {
        dp[1 << i][i][0] = 1;
    }

    for (int i=1; i<(1<<N); ++i) {
        for (int j=0; j<N; ++j) {
            if (((i >> j) & 1) == 0) continue;
            for (int k=0; k<N; ++k) {
                if (i & (1 << k)) continue;
                for (int l=0; l<=L; ++l) {
                    int diff = l - abs(A[j] - A[k]);
                    if (diff < 0) continue;
                    add(dp[i + (1 << k)][k][l], dp[i][j][diff]);
                }
            }
        }
    }

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

    cout << ans << endl;
}
/*
4 10
3 6 2 9

8 35
3 7 1 5 10 2 11 6
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 23012 KB Output is correct
2 Correct 201 ms 91132 KB Output is correct
3 Correct 138 ms 90980 KB Output is correct
4 Correct 204 ms 90980 KB Output is correct
5 Correct 205 ms 90976 KB Output is correct
6 Correct 190 ms 90980 KB Output is correct
7 Correct 125 ms 91016 KB Output is correct
8 Correct 139 ms 90980 KB Output is correct
9 Correct 169 ms 90980 KB Output is correct
10 Correct 185 ms 91128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 38 ms 23012 KB Output is correct
12 Correct 201 ms 91132 KB Output is correct
13 Correct 138 ms 90980 KB Output is correct
14 Correct 204 ms 90980 KB Output is correct
15 Correct 205 ms 90976 KB Output is correct
16 Correct 190 ms 90980 KB Output is correct
17 Correct 125 ms 91016 KB Output is correct
18 Correct 139 ms 90980 KB Output is correct
19 Correct 169 ms 90980 KB Output is correct
20 Correct 185 ms 91128 KB Output is correct
21 Incorrect 22 ms 22500 KB Output isn't correct
22 Halted 0 ms 0 KB -