답안 #1010332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010332 2024-06-28T19:54:14 Z tvladm2009 Skyscraper (JOI16_skyscraper) C++17
100 / 100
510 ms 210256 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int N = 100 + 7;
const int L = 2000 + 7; 
const int M = 1e9 + 7;

int n, l, a[N];
int dp[N][N][L][2][2];

int add(int a, int b) {
    a += b;
    if (a >= M) a -= M;
    if (a < 0) a += M;
    return a;
}

void addup(int &a, int b) {
    a = add(a, b);
}

int mul(int a, int b) {
    return (ll) a * b % M;
}

int mul(int a, int b, int c) {
    return mul(a, mul(b, c));
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> l;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    dp[1][0][0][0][0] = 1;
    dp[1][0][0][0][1] = 1;
    dp[1][0][0][1][0] = 1;
    dp[1][0][0][1][1] = 1;
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int s = 0; s <= l; ++s) {
                for (int S = 0; S <= 1; ++S) {
                    for (int F = 0; F <= 1; ++F) {
                        if (j > 0) { 
                            addup(dp[i + 1][j - 1][s + (2 * j + S + F) * (a[i + 1] - a[i])][S][F], mul(dp[i][j][s][S][F], j));
                        }
                        addup(dp[i + 1][j][s + (2 * j + S + F) * (a[i + 1] - a[i])][S][F], mul(dp[i][j][s][S][F], j, 2));
                        addup(dp[i + 1][j + 1][s + (2 * j + S + F) * (a[i + 1] - a[i])][S][F], mul(dp[i][j][s][S][F], j));
                    
                        if (S == 1) {
                            addup(dp[i + 1][j + 1][s + (2 * j + S + F) * (a[i + 1] - a[i])][0][F], dp[i][j][s][S][F]);
                            addup(dp[i + 1][j + 1][s + (2 * j + S + F) * (a[i + 1] - a[i])][1][F], dp[i][j][s][S][F]);
                            addup(dp[i + 1][j][s + (2 * j + S + F) * (a[i + 1] - a[i])][0][F], dp[i][j][s][S][F]);
                            addup(dp[i + 1][j][s + (2 * j + S + F) * (a[i + 1] - a[i])][1][F], dp[i][j][s][S][F]);
                        }
                        
                        if (F == 1) {
                            addup(dp[i + 1][j + 1][s + (2 * j + S + F) * (a[i + 1] - a[i])][S][0], dp[i][j][s][S][F]);
                            addup(dp[i + 1][j + 1][s + (2 * j + S + F) * (a[i + 1] - a[i])][S][1], dp[i][j][s][S][F]);
                            addup(dp[i + 1][j][s + (2 * j + S + F) * (a[i + 1] - a[i])][S][0], dp[i][j][s][S][F]);
                            addup(dp[i + 1][j][s + (2 * j + S + F) * (a[i + 1] - a[i])][S][1], dp[i][j][s][S][F]);
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= l; ++i) ans = add(ans, dp[n][0][i][0][0]);
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 4 ms 4444 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3676 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 2 ms 3676 KB Output is correct
5 Correct 2 ms 3676 KB Output is correct
6 Correct 1 ms 3676 KB Output is correct
7 Correct 1 ms 3420 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 2 ms 3420 KB Output is correct
10 Correct 2 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 4 ms 4444 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 1 ms 3676 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
14 Correct 2 ms 3676 KB Output is correct
15 Correct 2 ms 3676 KB Output is correct
16 Correct 1 ms 3676 KB Output is correct
17 Correct 1 ms 3420 KB Output is correct
18 Correct 1 ms 3420 KB Output is correct
19 Correct 2 ms 3420 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 6 ms 10332 KB Output is correct
22 Correct 270 ms 107344 KB Output is correct
23 Correct 482 ms 207956 KB Output is correct
24 Correct 394 ms 165004 KB Output is correct
25 Correct 504 ms 209672 KB Output is correct
26 Correct 399 ms 184300 KB Output is correct
27 Correct 135 ms 82772 KB Output is correct
28 Correct 155 ms 91732 KB Output is correct
29 Correct 300 ms 135684 KB Output is correct
30 Correct 510 ms 210256 KB Output is correct