답안 #44600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44600 2018-04-03T17:46:27 Z choikiwon Skyscraper (JOI16_skyscraper) C++17
0 / 100
378 ms 490728 KB
#include<bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int offset = 1000;

int N, L;
int A[102];

int cc[102][102][3010][2][2];
int dp(int n, int d, int sum, int s, int e) {
    if(e && sum >= L + offset) return 0;
    if(!e && sum >= L + offset + A[N - 1]) return 0;
    if(n == N) return !d && sum <= L + offset && s && e;
    int &ret = cc[n][d][sum][s][e];
    if(ret != -1) return ret;
    if(N - n < d) return ret = 0;

    int l = d;
    int r = d + e - s;

    if(n && l <= 0 && r <= 0) return ret = 0;

    ret = 0;
    if(!s) {
        ret += dp(n + 1, d + 1, A[n] + sum + 2 * (A[n + 1] - A[n]) * (d + 1), 1, e);
        ret %= mod;
        if(r) {
            ret += 1LL * (n == N - 1? r : r - e) * dp(n + 1, d, A[n] + sum + 2 * (A[n + 1] - A[n]) * d, 1, e) % mod;
            ret %= mod;
        }
    }
    if(!e) {
        ret += dp(n + 1, d, -A[n] + sum + 2 * (A[n + 1] - A[n]) * d, s, 1);
        ret %= mod;
        if(l) {
            ret += 1LL * (n == N - 1? l : l - s) * dp(n + 1, d - 1, -A[n] + sum + 2 * (A[n + 1] - A[n]) * (d - 1), s, 1) % mod;
            ret %= mod;
        }
    }
    if(l) {
        ret += 1LL * l * dp(n + 1, d, sum + 2 * (A[n + 1] - A[n]) * d, s, e) % mod;
        ret %= mod;
        if(s && !e) {
            ret += 1LL * r * dp(n + 1, d - 1, sum + 2 * (A[n + 1] - A[n]) * (d - 1), s, e) % mod;
            ret %= mod;
        }
        if(r) {
            ret += 1LL * min(l, r) * (n == N - 1? r : r - 1) % mod * dp(n + 1, d - 1, sum + 2 * (A[n + 1] - A[n]) * (d - 1), s, e) % mod;
            ret %= mod;
        }
    }
    if(r) {
        ret += 1LL * r * dp(n + 1, d, sum + 2 * (A[n + 1] - A[n]) * d, s, e) % mod;
        ret %= mod;
    }
    ret += dp(n + 1, d + 1, sum + 2 * (A[n + 1] - A[n]) * (d + 1), s, e);
    ret %= mod;

    return ret;
}

int main() {
    scanf("%d %d", &N, &L);

    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    if(N == 1) {
        printf("1");
        return 0;
    }

    sort(A, A + N);

    memset(cc, -1, sizeof(cc));
    printf("%d", dp(0, 0, offset, 0, 0));
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &L);
     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 378 ms 490728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 352 ms 490728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 378 ms 490728 KB Output isn't correct
3 Halted 0 ms 0 KB -