답안 #527003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527003 2022-02-16T19:32:58 Z FireGhost1301 Skyscraper (JOI16_skyscraper) C++11
15 / 100
1 ms 588 KB
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;
void add(int &x, int y) {
    x += y;
    while (x >= MOD) x -= MOD;
    while (x < 0) x += MOD;
}

int mul(int x, int y) {
    return (x * 1LL * y) % MOD;
}

const int N = 100 + 3, M = 1000 + 3;
int n, m, a[N];
int f[N][N][M][3];

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    a[n + 1] = a[n];

    f[0][0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
        int x = a[i + 2] - a[i + 1];
        for (int j = 0; j <= i; ++j) {
            for (int k = 0; k <= m; ++k) {
                for (int l = 0; l < 3; ++l) if (f[i][j][k][l]) {
                    if (k + (2 * j - l + 2) * x <= m)
                        add(f[i + 1][j + 1][k + (2 * j - l + 2) * x][l], mul(f[i][j][k][l], j - l + 1));
                    if (l < 2 && k + (2 * j - l + 1) * x <= m)
                        add(f[i + 1][j + 1][k + (2 * j - l + 1) * x][l + 1], mul(f[i][j][k][l], 2 - l));
                    if (k + (2 * j - l) * x <= m)
                        add(f[i + 1][j][k + (2 * j - l) * x][l], mul(f[i][j][k][l], 2 * j - l));
                    if (l < 2 && k + (2 * j - l - 1) * x <= m)
                        add(f[i + 1][j][k + (2 * j - l - 1) * x][l + 1], mul(f[i][j][k][l], 2 - l));
                    if (j - 1 > 0 && k + (2 * j - l - 2) * x <= m)
                        add(f[i + 1][j - 1][k + (2 * j - l - 2) * x][l], mul(f[i][j][k][l], j - 1));
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= m; ++i)
        add(ans, f[n][1][i][2]);
    
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 576 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 580 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 580 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -