Submission #982623

# Submission time Handle Problem Language Result Execution time Memory
982623 2024-05-14T14:04:18 Z dimashhh Skyscraper (JOI16_skyscraper) C++17
100 / 100
168 ms 87232 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e2 + 5, MOD = 1e9 + 7;

int n,l,a[N];
int dp[N][N][2][2][N*10];
void add(int &x,int y){
    x += y;
    if(x >= MOD) x -= MOD;
}
void test(){
    cin >> n >> l;
    for(int i = 1;i <= n;i++) {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    if(n == 1) {
        cout << 1;
        return;
    }
    if(a[2] - a[1] + a[2] - a[1] <= l) dp[2][1][0][0][(a[2]-a[1])*2] = 1;
    if(a[2] - a[1] <= l) dp[2][1][0][1][a[2]-a[1]] = dp[2][1][1][0][a[2]-a[1]] = 1;
    a[n+1] = 10000;
    for(int i = 2;i <= n;i++){
        for(int j = 1;j <= i;j++){
            for(int s = 0;s < 2;s++){
                for(int t = 0;t < 2;t++){
                    for(int k = 0;k <= l;k++){
                        int d = dp[i][j][s][t][k];
                        ll val = (a[i+1]-a[i]);
                        {//new
                            if(k+val*((j+1)*2-s-t) <= l) add(dp[i+1][j+1][s][t][k+val*((j+1)*2-s-t)],d*1ll*(j+1-s-t)%MOD);
                            if(!s){
                                if(k+val*((j+1)*2-1-t) <=l)add(dp[i+1][j+1][1][t][k+val*((j+1)*2-1-t)],d);
                            }
                            if(!t){
                                if(k+val*((j+1)*2-1-s) <= l)add(dp[i+1][j+1][s][1][k+val*((j+1)*2-1-s)],d);
                            }
                        }
                        {//merge
                            if(k+val*((j-1)*2-s-t)<=l)add(dp[i+1][j-1][s][t][k+val*((j-1)*2-s-t)],d*1ll*(j-1)%MOD);
                        }
                        {//corner
                            if(k+val*(2*j-s-t) <= l) add(dp[i+1][j][s][t][k+val*(2*j-s-t)],d*1ll*(j*2-s-t)%MOD);
                            if(!s){
                                if(k+val*(2*j-1-t) <= l) add(dp[i+1][j][1][t][k+val*(2*j-1-t)],d);
                            }
                            if(!t){
                                if(k+val*(2*j-1-s) <= l) add(dp[i+1][j][s][1][k+val*(2*j-1-s)],d);
                            }
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i = 1;i <= l;i++){
        add(ans,dp[n + 1][1][1][1][i]);
    }
    cout << ans;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int T = 1;
//    cin >> T;
    while (T--){
        test();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 2516 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 2 ms 2980 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 1 ms 3932 KB Output is correct
3 Correct 2 ms 4252 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 1 ms 3932 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 1 ms 3932 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 2 ms 4188 KB Output is correct
10 Correct 1 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 2516 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 2 ms 2980 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 2 ms 3932 KB Output is correct
12 Correct 1 ms 3932 KB Output is correct
13 Correct 2 ms 4252 KB Output is correct
14 Correct 1 ms 3676 KB Output is correct
15 Correct 1 ms 3932 KB Output is correct
16 Correct 2 ms 4188 KB Output is correct
17 Correct 1 ms 3932 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 1 ms 3676 KB Output is correct
21 Correct 8 ms 12984 KB Output is correct
22 Correct 112 ms 54784 KB Output is correct
23 Correct 153 ms 70736 KB Output is correct
24 Correct 134 ms 78020 KB Output is correct
25 Correct 168 ms 70064 KB Output is correct
26 Correct 137 ms 71764 KB Output is correct
27 Correct 73 ms 87232 KB Output is correct
28 Correct 82 ms 87144 KB Output is correct
29 Correct 127 ms 86812 KB Output is correct
30 Correct 156 ms 69900 KB Output is correct