답안 #975203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975203 2024-05-04T14:46:10 Z Beerus13 Skyscraper (JOI16_skyscraper) C++14
100 / 100
134 ms 51648 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][0] = 1;
    dp[1][1][0][1] = 2;
    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 > L) continue;
 
                    // connect 2 components
                    if(j) add(dp[i][j - 1][k + cost][z], 1ll * (j - 1) * dp[i - 1][j][k][z] % mod);
                    
                    // add a[i] at the beginning or end of one comp of permutation but don't lock
                    add(dp[i][j][k + cost][z], 1ll * (2 * j - z) * dp[i - 1][j][k][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 + cost][z + 1], 1ll * (2 - z) * dp[i - 1][j][k][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 + cost][z], 1ll * (2 - z) * dp[i - 1][j][k][z] % mod);
                    
                    // add a[i] at the beginning or end of permutation and lock
                    if(z < 2) add(dp[i][j + 1][k + cost][z + 1], 1ll * (2 - z) * dp[i - 1][j][k][z] % mod);
 
                    // add a[i] as a middle component
                    if(j >= 2) add(dp[i][j + 1][k + cost][z], 1ll * (j - 1) * dp[i - 1][j][k][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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 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 Correct 1 ms 2908 KB Output is correct
6 Correct 2 ms 2904 KB Output is correct
7 Correct 1 ms 2504 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 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 2908 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 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 Correct 1 ms 2908 KB Output is correct
6 Correct 2 ms 2904 KB Output is correct
7 Correct 1 ms 2504 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 1 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 3164 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 3 ms 5468 KB Output is correct
22 Correct 134 ms 42292 KB Output is correct
23 Correct 122 ms 48720 KB Output is correct
24 Correct 118 ms 51452 KB Output is correct
25 Correct 126 ms 48980 KB Output is correct
26 Correct 116 ms 48076 KB Output is correct
27 Correct 53 ms 35100 KB Output is correct
28 Correct 68 ms 38388 KB Output is correct
29 Correct 116 ms 51648 KB Output is correct
30 Correct 128 ms 48980 KB Output is correct