답안 #44598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44598 2018-04-03T17:30:45 Z choikiwon Skyscraper (JOI16_skyscraper) C++17
15 / 100
371 ms 491152 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(sum >= 3010) 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;

    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]);
    }

    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:62: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:65: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 Incorrect 345 ms 490748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 367 ms 490916 KB Output is correct
2 Correct 345 ms 490916 KB Output is correct
3 Correct 367 ms 491008 KB Output is correct
4 Correct 350 ms 491008 KB Output is correct
5 Correct 350 ms 491152 KB Output is correct
6 Correct 347 ms 491152 KB Output is correct
7 Correct 347 ms 491152 KB Output is correct
8 Correct 363 ms 491152 KB Output is correct
9 Correct 344 ms 491152 KB Output is correct
10 Correct 371 ms 491152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 345 ms 490748 KB Output isn't correct
2 Halted 0 ms 0 KB -