Submission #503083

# Submission time Handle Problem Language Result Execution time Memory
503083 2022-01-07T06:43:07 Z qwerasdfzxcl Skyscraper (JOI16_skyscraper) C++14
20 / 100
202 ms 168036 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);

        //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 1 ms 204 KB Output is correct
2 Correct 0 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 1 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 1 ms 1740 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 1740 KB Output is correct
5 Correct 2 ms 1740 KB Output is correct
6 Correct 2 ms 2124 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
8 Correct 3 ms 2380 KB Output is correct
9 Correct 2 ms 2508 KB Output is correct
10 Correct 2 ms 1936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 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 1 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 1 ms 1740 KB Output is correct
13 Correct 2 ms 2380 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 2 ms 2124 KB Output is correct
17 Correct 2 ms 1612 KB Output is correct
18 Correct 3 ms 2380 KB Output is correct
19 Correct 2 ms 2508 KB Output is correct
20 Correct 2 ms 1936 KB Output is correct
21 Correct 6 ms 9548 KB Output is correct
22 Correct 199 ms 141092 KB Output is correct
23 Correct 202 ms 142624 KB Output is correct
24 Incorrect 194 ms 168036 KB Output isn't correct
25 Halted 0 ms 0 KB -