답안 #418920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
418920 2021-06-06T08:42:57 Z lyc Skyscraper (JOI16_skyscraper) C++14
15 / 100
58 ms 130400 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];
    }

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

# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 130292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 130336 KB Output is correct
2 Correct 54 ms 130340 KB Output is correct
3 Correct 56 ms 130400 KB Output is correct
4 Correct 57 ms 130368 KB Output is correct
5 Correct 55 ms 130304 KB Output is correct
6 Correct 56 ms 130324 KB Output is correct
7 Correct 57 ms 130372 KB Output is correct
8 Correct 55 ms 130320 KB Output is correct
9 Correct 58 ms 130284 KB Output is correct
10 Correct 55 ms 130372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 130292 KB Output isn't correct
2 Halted 0 ms 0 KB -