Submission #133068

# Submission time Handle Problem Language Result Execution time Memory
133068 2019-07-20T06:20:31 Z PeppaPig Skyscraper (JOI16_skyscraper) C++14
100 / 100
378 ms 260616 KB
#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 105;
const int L = 1e3+5;
const int M = 1e9+7;

int n, l, a[N];
long dp[N][N][L][3];

long solve(int pos, int cc, int diff, int ends) {
    if(pos == n + 1) return (cc == 1 && diff <= l && ends == 2);
    if(cc == 0 || diff > l || ends == 3) return 0;
    long &now = dp[pos][cc][diff][ends];
    if(~now) return now;
    
    int ndiff = diff + (a[pos] - a[pos - 1]) * (2 * cc - ends);

    now = 0;
    now = (now + (cc + 1 - ends) * solve(pos + 1, cc + 1, ndiff, ends) % M) % M;
    now = (now + (2 * cc - ends) * solve(pos + 1, cc, ndiff, ends) % M) % M;
    now = (now + (cc - 1) * solve(pos + 1, cc - 1, ndiff, ends) % M) % M;
    now = (now + (2 - ends) * solve(pos + 1, cc + 1, ndiff, ends + 1) % M) % M;
    now = (now + (2 - ends) * solve(pos + 1, cc, ndiff, ends + 1) % M) % M;

    return now;
}

int main() {
    memset(dp, -1, sizeof dp);

    scanf("%d %d", &n, &l);
    for(int i = 1; i <= n; i++) scanf("%d", a + i);
    sort(a + 1, a + n + 1);

    if(n == 1) return !printf("1\n");
    printf("%lld\n", (solve(2, 1, 0, 0) + 2 * solve(2, 1, 0, 1)) % M);

    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:35: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:36:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%d", a + i);
                                 ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 245 ms 260472 KB Output is correct
2 Correct 211 ms 260552 KB Output is correct
3 Correct 209 ms 260472 KB Output is correct
4 Correct 209 ms 260536 KB Output is correct
5 Correct 211 ms 260496 KB Output is correct
6 Correct 210 ms 260488 KB Output is correct
7 Correct 213 ms 260472 KB Output is correct
8 Correct 211 ms 260444 KB Output is correct
9 Correct 213 ms 260492 KB Output is correct
10 Correct 214 ms 260556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 260544 KB Output is correct
2 Correct 211 ms 260520 KB Output is correct
3 Correct 209 ms 260556 KB Output is correct
4 Correct 210 ms 260500 KB Output is correct
5 Correct 210 ms 260492 KB Output is correct
6 Correct 210 ms 260472 KB Output is correct
7 Correct 210 ms 260536 KB Output is correct
8 Correct 210 ms 260604 KB Output is correct
9 Correct 212 ms 260552 KB Output is correct
10 Correct 213 ms 260528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 245 ms 260472 KB Output is correct
2 Correct 211 ms 260552 KB Output is correct
3 Correct 209 ms 260472 KB Output is correct
4 Correct 209 ms 260536 KB Output is correct
5 Correct 211 ms 260496 KB Output is correct
6 Correct 210 ms 260488 KB Output is correct
7 Correct 213 ms 260472 KB Output is correct
8 Correct 211 ms 260444 KB Output is correct
9 Correct 213 ms 260492 KB Output is correct
10 Correct 214 ms 260556 KB Output is correct
11 Correct 210 ms 260544 KB Output is correct
12 Correct 211 ms 260520 KB Output is correct
13 Correct 209 ms 260556 KB Output is correct
14 Correct 210 ms 260500 KB Output is correct
15 Correct 210 ms 260492 KB Output is correct
16 Correct 210 ms 260472 KB Output is correct
17 Correct 210 ms 260536 KB Output is correct
18 Correct 210 ms 260604 KB Output is correct
19 Correct 212 ms 260552 KB Output is correct
20 Correct 213 ms 260528 KB Output is correct
21 Correct 212 ms 260444 KB Output is correct
22 Correct 378 ms 260556 KB Output is correct
23 Correct 297 ms 260616 KB Output is correct
24 Correct 307 ms 260568 KB Output is correct
25 Correct 297 ms 260572 KB Output is correct
26 Correct 283 ms 260600 KB Output is correct
27 Correct 246 ms 260564 KB Output is correct
28 Correct 265 ms 260600 KB Output is correct
29 Correct 327 ms 260600 KB Output is correct
30 Correct 300 ms 260472 KB Output is correct