Submission #503084

# Submission time Handle Problem Language Result Execution time Memory
503084 2022-01-07T06:44:12 Z qwerasdfzxcl Skyscraper (JOI16_skyscraper) C++14
100 / 100
228 ms 197812 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const int MOD = 1e9+7;
ll dp[102][102][3][1002], a[102];

inline void add(ll &x, ll y){
    x += y;
    if (x>=MOD) x -= MOD;
}

int main(){
    int n, L;
    scanf("%d %d", &n, &L);
    for (int i=1;i<=n;i++) scanf("%lld", a+i);
    if (n==1) {printf("1\n"); return 0;}
    sort(a+1, a+n+1);

    dp[n-1][0][1][(a[n]-a[n-1])] = 1;
    if (a[n]-a[n-1]*2<=L) dp[n-1][0][2][(a[n]-a[n-1])*2] = 1;

    for (int i=n-2;i;i--){
        for (int j=0;j<=n;j++){
            int val0 = (a[i+1] - a[i]) * (j*2);
            int val1 = (a[i+1] - a[i]) * (j*2 + 1);
            int val2 = (a[i+1] - a[i]) * (j*2 + 2);

            if (j){
            for (int k=val0;k<=L;k++){
                add(dp[i][j][0][k], dp[i+1][j+1][0][k-val0] * (j+1) %MOD);
                add(dp[i][j][0][k], dp[i+1][j][0][k-val0] * (j*2) %MOD);
                add(dp[i][j][0][k], dp[i+1][j-1][0][k-val0] * (j-1) %MOD);

                add(dp[i][j][0][k], dp[i+1][j][1][k-val0] *2 %MOD);
                add(dp[i][j][0][k], dp[i+1][j-1][1][k-val0] *2 %MOD);
            }}

            for (int k=val1;k<=L;k++){
                add(dp[i][j][1][k], dp[i+1][j+1][1][k-val1] * (j+1) %MOD);
                add(dp[i][j][1][k], dp[i+1][j][1][k-val1] * (j*2+1) %MOD);
                if (j) add(dp[i][j][1][k], dp[i+1][j-1][1][k-val1] * j %MOD);

                add(dp[i][j][1][k], dp[i+1][j][2][k-val1]);
                if (j) add(dp[i][j][1][k], dp[i+1][j-1][2][k-val1]);
            }

            for (int k=val2;k<=L;k++){
                add(dp[i][j][2][k], dp[i+1][j+1][2][k-val2] * (j+1) %MOD);
                add(dp[i][j][2][k], dp[i+1][j][2][k-val2] * (j*2+2) %MOD);
                if (j) add(dp[i][j][2][k], dp[i+1][j-1][2][k-val2] * (j+1) %MOD);
            }
        }
    }

    ll ans = 0;
    for (int k=0;k<=L;k++){
        add(ans, dp[1][1][0][k]);
        add(ans, dp[1][0][1][k]*2%MOD);

        //if (k<=10) printf("%d %d\n", dp[1][1][0][k], dp[1][0][1][k]);
    }

    printf("%lld\n", ans);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d %d", &n, &L);
      |     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:16:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     for (int i=1;i<=n;i++) scanf("%lld", a+i);
      |                            ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 2 ms 844 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1996 KB Output is correct
2 Correct 2 ms 1740 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 1 ms 1808 KB Output is correct
5 Correct 2 ms 1868 KB Output is correct
6 Correct 2 ms 2124 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 2 ms 2380 KB Output is correct
9 Correct 2 ms 2508 KB Output is correct
10 Correct 1 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 2 ms 844 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 1 ms 1996 KB Output is correct
12 Correct 2 ms 1740 KB Output is correct
13 Correct 2 ms 2380 KB Output is correct
14 Correct 1 ms 1808 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 2124 KB Output is correct
17 Correct 1 ms 1612 KB Output is correct
18 Correct 2 ms 2380 KB Output is correct
19 Correct 2 ms 2508 KB Output is correct
20 Correct 1 ms 1868 KB Output is correct
21 Correct 7 ms 9548 KB Output is correct
22 Correct 226 ms 141068 KB Output is correct
23 Correct 188 ms 142716 KB Output is correct
24 Correct 191 ms 168076 KB Output is correct
25 Correct 205 ms 145284 KB Output is correct
26 Correct 175 ms 144680 KB Output is correct
27 Correct 121 ms 152304 KB Output is correct
28 Correct 155 ms 165208 KB Output is correct
29 Correct 228 ms 197812 KB Output is correct
30 Correct 193 ms 144476 KB Output is correct