Submission #866846

# Submission time Handle Problem Language Result Execution time Memory
866846 2023-10-27T08:44:25 Z prohacker Skyscraper (JOI16_skyscraper) C++14
100 / 100
125 ms 46164 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double

using namespace std;

const int N = 105;
const int INF = INT_MAX;
const int mod = 1e9+7;

int n,lim,dp[N][N][1010][3],a[N];
int ans;

void add(int &x, const int y) {
    x += y;
    if(x >= mod) {
        x -= mod;
    }
}

signed main()
{
    if (fopen("task.inp", "r")) {
        freopen("task.inp", "r", stdin);
        freopen("task.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> lim;
    if(n == 1) {
        cout << 1;
        return 0;
    }
    for(int i = 1 ; i <= n ; i++) {
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    a[n+1] = 10010;
    dp[0][0][0][0] = 1;
    for(int i = 1 ; i <= n ; i++) {
        for(int j = 1 ; j <= i ; j++) {
            for(int k = 0 ; k <= lim ; k++) {
                for(int m = 0 ; m <= 2 ; m++) {
                    int delta = (2*j-m)*(a[i+1]-a[i]);
                    if(delta > k) {
                        continue;
                    }
                    add(dp[i][j][k][m],dp[i-1][j-1][k-delta][m]);
                    add(dp[i][j][k][m],1LL*(2*j-m)*dp[i-1][j][k-delta][m]%mod);
                    if(m > 0) {
                        if(j > 0) {
                            add(dp[i][j][k][m],1LL*(3-m)*dp[i-1][j-1][k-delta][m-1]%mod);
                        }
                        if(m == 1) {
                            add(dp[i][j][k][m],1LL*2*j*dp[i-1][j][k-delta][m-1]%mod);
                        }
                        else {
                            if(i == n) {
                                add(dp[i][j][k][m],dp[i-1][j][k-delta][m-1]);
                            }
                            else {
                                if(j > 0) {
                                    add(dp[i][j][k][m],1LL*(j-1)*dp[i-1][j][k-delta][m-1]%mod);
                                }
                            }
                        }
                    }
                    if(m == 2) {
                        if(i == n) {
                            add(dp[i][j][k][m],dp[i-1][j+1][k-delta][m]);
                        }
                        else {
                            add(dp[i][j][k][m],1LL*j*(j-1)*dp[i-1][j+1][k-delta][m]%mod);
                        }
                    }
                    else if(m == 1) {
                        add(dp[i][j][k][m],1LL*j*j*dp[i-1][j+1][k-delta][m]%mod);
                    }
                    else {
                        add(dp[i][j][k][m],1LL*j*(j+1)*dp[i-1][j+1][k-delta][m]%mod);
                    }
                }
            }
        }
    }
    for(int i = 0 ; i <= lim ; i++) {
        add(ans,dp[n][1][i][2]);
    }
    cout << ans;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen("task.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 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 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 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 860 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 684 KB Output is correct
6 Correct 1 ms 776 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 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 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 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 860 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 684 KB Output is correct
16 Correct 1 ms 776 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 2904 KB Output is correct
22 Correct 96 ms 35896 KB Output is correct
23 Correct 125 ms 42780 KB Output is correct
24 Correct 105 ms 45904 KB Output is correct
25 Correct 111 ms 42868 KB Output is correct
26 Correct 98 ms 42476 KB Output is correct
27 Correct 48 ms 30944 KB Output is correct
28 Correct 54 ms 33872 KB Output is correct
29 Correct 98 ms 46164 KB Output is correct
30 Correct 112 ms 43344 KB Output is correct