Submission #975190

# Submission time Handle Problem Language Result Execution time Memory
975190 2024-05-04T14:37:36 Z Beerus13 Skyscraper (JOI16_skyscraper) C++14
15 / 100
1 ms 3164 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 5;
const int mod = 1e9 + 7;
 
void add(int &a, int b) {
    a += b;
    if(a >= mod) a -= mod;
    if(a < 0) a += mod;
}
 
int n, L, a[N];
int dp[N][N][N * 10][3];
 
void solve() {
    cin >> n >> L;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    if(n == 1) return cout << 1 << '\n', void();
    sort(a + 1, a + n + 1);
    dp[1][1][0][1] = 2;
    dp[1][1][0][0] = 1;
    for(int i = 2; i <= n; ++i) {
        for(int j = 0; j <= i; ++j) {
            for(int k = 0; k <= L; ++k) {
                for(int z = 0; z <= 2; ++z) {
                    int cost = (2 * j - z) * (a[i] - a[i - 1]);
                    if(k - cost < 0) continue;
 
                    // connect 2 components
                    if(j) add(dp[i][j - 1][k][z], 1ll * (j - 1) * dp[i - 1][j][k - cost][z] % mod);
                    
                    // add a[i] at the beginning or end of one comp of permutation but don't lock
                    add(dp[i][j][k][z], 1ll * (2 * j - z) * dp[i - 1][j][k - cost][z] % mod);
                    
                    // add a[i] at the beginning or end of one comp of permutation and lock
                    if(z < 2) add(dp[i][j][k][z + 1], 1ll * (2 - z) * dp[i - 1][j][k - cost][z] % mod);
 
                    // create new component
 
                    // add a[i] at the beginning or end of permutation but don't lock
                    add(dp[i][j + 1][k][z], 1ll * (2 - z) * dp[i - 1][j][k - cost][z] % mod);
                    
                    // add a[i] at the beginning or end of permutation and lock
                    if(z < 2) add(dp[i][j + 1][k][z + 1], 1ll * (2 - z) * dp[i - 1][j][k - cost][z] % mod);
 
                    // add a[i] as a middle component
                    if(j >= 2) add(dp[i][j + 1][k][z], 1ll * (j - 1) * dp[i - 1][j][k - cost][z] % mod);
                }
            }
        }
    }
    int res = 0;
    for(int i = 0; i <= L; ++i) {
        add(res, dp[n][1][i][2]);
    }
    cout << res << '\n';
}
 
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int test = 1;
    // cin >> test;
    while(test--) solve();
    return 0;
}
// https://oj.uz/problem/view/JOI16_skyscraper
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 1 ms 2908 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 3024 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 1 ms 2908 KB Output isn't correct
6 Halted 0 ms 0 KB -