Submission #1090755

# Submission time Handle Problem Language Result Execution time Memory
1090755 2024-09-18T16:51:39 Z BF001 Skyscraper (JOI16_skyscraper) C++17
100 / 100
202 ms 199392 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define N 105
#define M 1005

int dp[3][N][N][M], n, l, a[N], md = 1e9 + 7;

void add(int& a, int b){
    a += b;
    if (a >= md) a -= md;
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
 
    cin >> n >> l;
    dp[0][0][0][0] = 1;

    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] = 1e9;

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            for (int typ = 0; typ <= 2; typ++){
                int cst = (a[i + 1] - a[i]) * (2 * j - typ);
                for (int s = cst; s <= l; s++){
                    add(dp[typ][i][j][s], dp[typ][i - 1][j - 1][s - cst]);
                    add(dp[typ][i][j][s], dp[typ][i - 1][j][s - cst] * (2 * j - typ) % md);
                    if (typ) add(dp[typ][i][j][s], dp[typ - 1][i - 1][j - 1][s - cst] * (3 - typ) % md);
                    else{
                        add(dp[typ][i][j][s], dp[typ][i - 1][j + 1][s - cst] * j % md * (j + 1) % md);
                    }
                    if (typ == 1){
                        add(dp[typ][i][j][s], dp[typ - 1][i - 1][j][s - cst] * 2 * j % md);
                        add(dp[typ][i][j][s], dp[typ][i - 1][j + 1][s - cst] * j % md * j % md);
                    }
                    if (typ == 2){
                        if (i != n) add(dp[typ][i][j][s], dp[typ][i - 1][j + 1][s - cst] * j % md * (j - 1) % md);
                        if (i == n) 
                        {
                            add(dp[typ][i][j][s], dp[typ][i - 1][j + 1][s - cst]);
                            add(dp[typ][i][j][s], dp[typ - 1][i - 1][j][s - cst]);
                        }
                        else 
                            add(dp[typ][i][j][s], dp[typ - 1][i - 1][j][s - cst] * (j - 1) % md);
                    }
                }
            }
        }
    }

    int res = 0;
    for (int i = 0; i <= l; i++) add(res, dp[2][n][1][i]);
    
    cout << res;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 2 ms 1228 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2140 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 1 ms 2140 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 1 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 2 ms 1228 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 2140 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 1884 KB Output is correct
15 Correct 1 ms 2140 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 1 ms 1884 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 1 ms 2140 KB Output is correct
21 Correct 5 ms 10328 KB Output is correct
22 Correct 196 ms 142680 KB Output is correct
23 Correct 181 ms 144720 KB Output is correct
24 Correct 191 ms 170836 KB Output is correct
25 Correct 190 ms 147024 KB Output is correct
26 Correct 172 ms 148568 KB Output is correct
27 Correct 109 ms 152860 KB Output is correct
28 Correct 139 ms 165880 KB Output is correct
29 Correct 202 ms 199392 KB Output is correct
30 Correct 193 ms 147028 KB Output is correct