Submission #418923

# Submission time Handle Problem Language Result Execution time Memory
418923 2021-06-06T08:46:44 Z lyc Skyscraper (JOI16_skyscraper) C++14
20 / 100
206 ms 130608 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
const int mod = 1e9+7;

const int mxN = 105;
const int mxL = 1005;
const int mxA = 1005;

int N, L, A[mxN];
int res[mxN][mxN][mxL][3];

// processing ith element, j connected component, k cost, l ends open
int dp(int i, int j, int k, int l) {
    if (k > L || l < 0) return 0;
    if (i > N) return j == 1 && l == 0;

    int& ans = res[i][j][k][l];
    if (~ans) return ans;
    ans = 0;

    int opened = 2*j - 2 + l;
    int kk = k + opened * (A[i]-A[i-1]);

    // new cc
    ans += (long long) (j+1 - 2 + l) * dp(i+1, j+1, kk, l);
    ans %= mod;
    ans += l * dp(i+1, j+1, kk, l-1) % mod;
    ans %= mod;

    if (j > 0) {
        // append
        ans += (long long) opened * dp(i+1, j, kk, l) % mod;
        ans %= mod;
        ans += l * dp(i+1, j, kk, l-1) % mod;
        ans %= mod;
    }

    if (j > 1) {
        // join
        ans += (long long) (j-1) * dp(i+1, j-1, kk, l) % mod;
        ans %= mod;
    }

    //TRACE(i _ j _ k _ l _ ans);
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin >> N >> L;
    FOR(i,1,N){
        cin >> A[i];
    }

    // corner case -- cannot close both ends simultaneously
    if (N == 1) {
        cout << 1 << '\n';
        return 0;
    }

    sort(A+1,A+1+N);
    memset(res,-1,sizeof res);
    cout << dp(1,0,0,2) << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 55 ms 130372 KB Output is correct
3 Correct 55 ms 130372 KB Output is correct
4 Correct 56 ms 130340 KB Output is correct
5 Correct 55 ms 130372 KB Output is correct
6 Correct 56 ms 130336 KB Output is correct
7 Correct 54 ms 130300 KB Output is correct
8 Correct 55 ms 130384 KB Output is correct
9 Correct 54 ms 130400 KB Output is correct
10 Correct 54 ms 130312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 130368 KB Output is correct
2 Correct 55 ms 130372 KB Output is correct
3 Correct 56 ms 130608 KB Output is correct
4 Correct 55 ms 130296 KB Output is correct
5 Correct 56 ms 130336 KB Output is correct
6 Correct 54 ms 130372 KB Output is correct
7 Correct 55 ms 130464 KB Output is correct
8 Correct 54 ms 130332 KB Output is correct
9 Correct 57 ms 130328 KB Output is correct
10 Correct 63 ms 130284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 55 ms 130372 KB Output is correct
3 Correct 55 ms 130372 KB Output is correct
4 Correct 56 ms 130340 KB Output is correct
5 Correct 55 ms 130372 KB Output is correct
6 Correct 56 ms 130336 KB Output is correct
7 Correct 54 ms 130300 KB Output is correct
8 Correct 55 ms 130384 KB Output is correct
9 Correct 54 ms 130400 KB Output is correct
10 Correct 54 ms 130312 KB Output is correct
11 Correct 56 ms 130368 KB Output is correct
12 Correct 55 ms 130372 KB Output is correct
13 Correct 56 ms 130608 KB Output is correct
14 Correct 55 ms 130296 KB Output is correct
15 Correct 56 ms 130336 KB Output is correct
16 Correct 54 ms 130372 KB Output is correct
17 Correct 55 ms 130464 KB Output is correct
18 Correct 54 ms 130332 KB Output is correct
19 Correct 57 ms 130328 KB Output is correct
20 Correct 63 ms 130284 KB Output is correct
21 Correct 55 ms 130372 KB Output is correct
22 Incorrect 206 ms 130308 KB Output isn't correct
23 Halted 0 ms 0 KB -