Submission #44601

# Submission time Handle Problem Language Result Execution time Memory
44601 2018-04-03T17:47:19 Z choikiwon Skyscraper (JOI16_skyscraper) C++17
100 / 100
704 ms 491116 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]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 335 ms 490728 KB Output is correct
3 Correct 343 ms 490728 KB Output is correct
4 Correct 339 ms 490740 KB Output is correct
5 Correct 346 ms 490776 KB Output is correct
6 Correct 339 ms 490776 KB Output is correct
7 Correct 341 ms 490776 KB Output is correct
8 Correct 347 ms 490776 KB Output is correct
9 Correct 346 ms 490904 KB Output is correct
10 Correct 353 ms 490904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 339 ms 490904 KB Output is correct
2 Correct 348 ms 490916 KB Output is correct
3 Correct 340 ms 490916 KB Output is correct
4 Correct 336 ms 490916 KB Output is correct
5 Correct 377 ms 490916 KB Output is correct
6 Correct 351 ms 490916 KB Output is correct
7 Correct 339 ms 490916 KB Output is correct
8 Correct 340 ms 490916 KB Output is correct
9 Correct 338 ms 490916 KB Output is correct
10 Correct 373 ms 490916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 335 ms 490728 KB Output is correct
3 Correct 343 ms 490728 KB Output is correct
4 Correct 339 ms 490740 KB Output is correct
5 Correct 346 ms 490776 KB Output is correct
6 Correct 339 ms 490776 KB Output is correct
7 Correct 341 ms 490776 KB Output is correct
8 Correct 347 ms 490776 KB Output is correct
9 Correct 346 ms 490904 KB Output is correct
10 Correct 353 ms 490904 KB Output is correct
11 Correct 339 ms 490904 KB Output is correct
12 Correct 348 ms 490916 KB Output is correct
13 Correct 340 ms 490916 KB Output is correct
14 Correct 336 ms 490916 KB Output is correct
15 Correct 377 ms 490916 KB Output is correct
16 Correct 351 ms 490916 KB Output is correct
17 Correct 339 ms 490916 KB Output is correct
18 Correct 340 ms 490916 KB Output is correct
19 Correct 338 ms 490916 KB Output is correct
20 Correct 373 ms 490916 KB Output is correct
21 Correct 364 ms 490916 KB Output is correct
22 Correct 704 ms 490916 KB Output is correct
23 Correct 570 ms 491116 KB Output is correct
24 Correct 572 ms 491116 KB Output is correct
25 Correct 600 ms 491116 KB Output is correct
26 Correct 554 ms 491116 KB Output is correct
27 Correct 436 ms 491116 KB Output is correct
28 Correct 470 ms 491116 KB Output is correct
29 Correct 591 ms 491116 KB Output is correct
30 Correct 587 ms 491116 KB Output is correct