Submission #1013908

# Submission time Handle Problem Language Result Execution time Memory
1013908 2024-07-04T08:02:00 Z Baytoro Skyscraper (JOI16_skyscraper) C++17
100 / 100
43 ms 24104 KB
//resolve it

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define int ll
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
const int N=105,mod=1e9+7;
int dp[N][N][1005][3];
void solve(){
    int n,l;cin>>n>>l;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    if(n==1) {
        cout<<1<<endl;
        return;
    }
    sort(all(a));
    if(a[1]-a[0]<=l) dp[1][1][a[1]-a[0]][1]=2;
    if(2*(a[1]-a[0])<=l) dp[1][1][2*(a[1]-a[0])][0]=1;
    a.pb(10000);
    for(int i=1;i<n;i++) {
        int d=(a[i+1]-a[i]);
        for(int j=1;j<=i;j++) {
            for(int s=0;s<=l;s++) {
                for(int f=0;f<3;f++) {
                    if(!dp[i][j][s][f]) continue;
                    //add to ends

                    if(f<2 && s+d*(2*j-f-1)<=l) {
                        if(i==n-1) {
                            dp[i+1][j][s+d*(2*j-f-1)][f+1]+=(dp[i][j][s][f]*(2-f)*j);
                            dp[i+1][j][s+d*(2*j-f-1)][f+1]%=mod;
                        }

                        else if(f==0 || j>1) {
                            dp[i+1][j][s+d*(2*j-f-1)][f+1]+=(dp[i][j][s][f]*(2-f)*(j-f));
                            dp[i+1][j][s+d*(2*j-f-1)][f+1]%=mod;
                        }

                        if(s+d*(2*j-f+1)<=l) {
                            dp[i+1][j+1][s+d*(2*j-f+1)][f+1]+=(dp[i][j][s][f]*(2-f));
                            dp[i+1][j+1][s+d*(2*j-f+1)][f+1]%=mod;
                        }
                    }
                    //create
                    if(s+d*(2*j-f+2)<=l) {
                        dp[i+1][j+1][s+d*(2*j-f+2)][f]+=dp[i][j][s][f];
                        dp[i+1][j+1][s+d*(2*j-f+2)][f]%=mod;
                    }

                    //add
                    if(s+d*(2*j-f)<=l) {//<-
                        dp[i+1][j][s+d*(2*j-f)][f]+=dp[i][j][s][f]*(2*j-f);
                        dp[i+1][j][s+d*(2*j-f)][f]%=mod;
                    }

                    //merge
                    if(s+d*(2*j-f-2)<=l && j>=2 && (i==n-1 || j>2 || f<2)) {
                        if(f==0) {
                            dp[i+1][j-1][s+d*(2*j-f-2)][f]+=dp[i][j][s][f]*(j-1)*j;
                            dp[i+1][j-1][s+d*(2*j-f-2)][f]%=mod;
                        }
                        if(f==1) {
                            dp[i+1][j-1][s+d*(2*j-f-2)][f]+=dp[i][j][s][f]*(j-1)*(j-1);
                            dp[i+1][j-1][s+d*(2*j-f-2)][f]%=mod;
                        }
                        if(f==2) {
                            if(i==n-1) {
                                dp[i+1][j-1][s+d*(2*j-f-2)][f]+=dp[i][j][s][f];
                                dp[i+1][j-1][s+d*(2*j-f-2)][f]%=mod;
                            }
                            else {
                                dp[i+1][j-1][s+d*(2*j-f-2)][f]+=dp[i][j][s][f]*(j-1)*(j-2);
                                dp[i+1][j-1][s+d*(2*j-f-2)][f]%=mod;
                            }
                        }
                    }
                }
            }
        }
    }
    int ans=0;
    for(int i=0;i<=l;i++) {
        ans+=dp[n][1][i][2];
        ans%=mod;
    }
    cout<<ans<<endl;
}
signed main(){
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
}
//#endif
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 700 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 700 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 28 ms 24104 KB Output is correct
23 Correct 22 ms 8060 KB Output is correct
24 Correct 21 ms 12120 KB Output is correct
25 Correct 23 ms 9308 KB Output is correct
26 Correct 29 ms 8488 KB Output is correct
27 Correct 21 ms 9684 KB Output is correct
28 Correct 15 ms 12124 KB Output is correct
29 Correct 43 ms 16432 KB Output is correct
30 Correct 37 ms 9308 KB Output is correct