답안 #902584

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
902584 2024-01-10T18:29:15 Z Spade1 Skyscraper (JOI16_skyscraper) C++14
20 / 100
458 ms 377684 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll ll>
#define st first
#define nd second
#define pb push_back
using namespace std;

const int maxN = 1e2 + 10;
const int maxL = 1e3 + 10;
const int M = 1e9 + 7;

ll dp[maxN][maxN][3*maxL][3], a[maxN];

void solve() {
    ll n, l; cin >> n >> l;
    if (n == 1) {
        cout << 1 << '\n';
        return;
    }
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a+1, a+n+1);
    dp[0][0][2*l][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int k = 0; k <= 3*l; ++k) {
                if (k+2*a[i] <= 3*l) {
                    dp[i][j][k][0] = (dp[i][j][k][0] + j*dp[i-1][j-1][k+2*a[i]][0]) % M;
                    dp[i][j][k][1] = (dp[i][j][k][1] + (j-1)*dp[i-1][j-1][k+2*a[i]][1]) % M;
                    dp[i][j][k][2] = (dp[i][j][k][2] + (j-2)*dp[i-1][j-1][k+2*a[i]][2]) % M;
                }
                if (k+a[i] <= 3*l) {
                    dp[i][j][k][1] = (dp[i][j][k][1] + 2*dp[i-1][j-1][k+a[i]][0]) % M;
                    dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j-1][k+a[i]][1]) % M;
                }
                dp[i][j][k][0] = (dp[i][j][k][0] + (2*j)*dp[i-1][j][k][0]) % M;
                dp[i][j][k][1] = (dp[i][j][k][1] + (2*j-1)*dp[i-1][j][k][1]) % M;
                dp[i][j][k][2] = (dp[i][j][k][2] + (2*j-2)*dp[i-1][j][k][2]) % M;
                if (k-a[i] >= 0) {
                    dp[i][j][k][1] = (dp[i][j][k][1] + 2*dp[i-1][j][k-a[i]][0]) % M;
                    dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j][k-a[i]][1]) % M;
                }
                if (k-2*a[i] >= 0) {
                    dp[i][j][k][0] = (dp[i][j][k][0] + j*dp[i-1][j+1][k-2*a[i]][0]) % M;
                    dp[i][j][k][1] = (dp[i][j][k][1] + j*dp[i-1][j+1][k-2*a[i]][1]) % M;
                    dp[i][j][k][2] = (dp[i][j][k][2] + j*dp[i-1][j+1][k-2*a[i]][2]) % M;
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 2*l; i <= 3*l; ++i) {
        ans += dp[n][1][i][2];
        ans %= M;
    }
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 1016 KB Output is correct
5 Correct 6 ms 4956 KB Output is correct
6 Correct 6 ms 4440 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 5 ms 4696 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1624 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 2 ms 1880 KB Output is correct
4 Correct 3 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 2 ms 1880 KB Output is correct
9 Correct 3 ms 2284 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 1016 KB Output is correct
5 Correct 6 ms 4956 KB Output is correct
6 Correct 6 ms 4440 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 5 ms 4696 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 2 ms 1624 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 2 ms 1880 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 1 ms 1628 KB Output is correct
18 Correct 2 ms 1880 KB Output is correct
19 Correct 3 ms 2284 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 11 ms 11528 KB Output is correct
22 Incorrect 458 ms 377684 KB Output isn't correct
23 Halted 0 ms 0 KB -