Submission #631581

# Submission time Handle Problem Language Result Execution time Memory
631581 2022-08-18T09:20:47 Z bachhoangxuan Skyscraper (JOI16_skyscraper) C++17
100 / 100
178 ms 6556 KB
#include<bits/stdc++.h>
using namespace std;
#define maxn 105
#define maxl 1005
#define int long long
const int mod=1e9+7;
int dp[2][maxn][maxl][2][2],n,a[maxn],l,t;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin >> n >> l;
    for(int i=1;i<=n;i++) cin >> a[i];
    sort(a+1,a+n+1);
    for(int p=0;p<=1;p++){
        for(int q=0;q<=1;q++) dp[1][1][0][p][q]=1;
    }
    for(int i=1;i<n;i++){
        t^=1;
        for(int j=1;j<=i;j++){
            for(int k=0;k<=l;k++){
                for(int p=0;p<=1;p++){
                    for(int q=0;q<=1;q++){
                        int nk=k+(2*j-p-q)*(a[i+1]-a[i]);
                        int v=dp[t][j][k][p][q];dp[t][j][k][p][q]=0;
                        if(nk>l) continue;
                        dp[t^1][j][nk][p][q]=(dp[t^1][j][nk][p][q]+(2*j-p-q)*v)%mod;
                        dp[t^1][j-1][nk][p][q]=(dp[t^1][j-1][nk][p][q]+(j-1)*v)%mod;
                        dp[t^1][j+1][nk][p][q]=(dp[t^1][j+1][nk][p][q]+(j+1-p-q)*v)%mod;
                        if(!p){
                            dp[t^1][j][nk][1][q]=(dp[t^1][j][nk][1][q]+v)%mod;
                            dp[t^1][j+1][nk][1][q]=(dp[t^1][j+1][nk][1][q]+v)%mod;
                        }
                        if(!q){
                            dp[t^1][j][nk][p][1]=(dp[t^1][j][nk][p][1]+v)%mod;
                            dp[t^1][j+1][nk][p][1]=(dp[t^1][j+1][nk][p][1]+v)%mod;
                        }
                    }
                }
            }
        }
    }
    int ans=0;t^=1;
    for(int i=0;i<=l;i++) ans=(ans+dp[t][1][i][1][1])%mod;
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 712 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 712 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 428 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 452 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 112 ms 4852 KB Output is correct
23 Correct 146 ms 6556 KB Output is correct
24 Correct 135 ms 5668 KB Output is correct
25 Correct 149 ms 6516 KB Output is correct
26 Correct 142 ms 6316 KB Output is correct
27 Correct 43 ms 2628 KB Output is correct
28 Correct 59 ms 2956 KB Output is correct
29 Correct 106 ms 4656 KB Output is correct
30 Correct 178 ms 6468 KB Output is correct