답안 #168846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168846 2019-12-16T16:34:26 Z srvlt Skyscraper (JOI16_skyscraper) C++14
100 / 100
336 ms 250460 KB
#include <bits/stdc++.h>

#define ll long long
#define db double
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"

#define int long long

using namespace std;

const int N = 103, K = 1003, MOD = 1e9 + 7;
int n, r, a[N], dp[N][N][K][3];

void add(int & x, int y) {
    x += y;
    if (x >= MOD) {
        x %= MOD;
    }
}

int calc(int i, int j, int k, int l) {
    if (i > 0 && (j < 1 || l > 2 || k > r)) {
        return 0;
    }
    if (i == n) {
        return j == 1 && l == 2;
    }
    int & res = dp[i][j][k][l];
    if (res != -1) {
        return res;
    }
    int s = (a[i + 1] - a[i]) * (2 * j - l) + k;
    res = 0;
    add(res, (j + 1 - l) * calc(i + 1, j + 1, s, l));
    add(res, (2 - l) * calc(i + 1, j, s, l + 1));
    add(res, (2 - l) * calc(i + 1, j + 1, s, l + 1));
    add(res, (j - 1) * calc(i + 1, j - 1, s, l));
    add(res, (2 * j - l) * calc(i + 1, j, s, l));
    return res;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp, -1, sizeof(dp));
    cin >> n >> r;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    if (n == 1) {
        cout << 1;
        return 0;
    }
    sort(a + 1, a + n + 1);
    a[0] = a[1];
    cout << calc(0, 0, 0, 0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 250364 KB Output is correct
2 Correct 211 ms 250232 KB Output is correct
3 Correct 212 ms 250232 KB Output is correct
4 Correct 213 ms 250204 KB Output is correct
5 Correct 212 ms 250232 KB Output is correct
6 Correct 213 ms 250232 KB Output is correct
7 Correct 212 ms 250460 KB Output is correct
8 Correct 213 ms 250332 KB Output is correct
9 Correct 212 ms 250232 KB Output is correct
10 Correct 215 ms 250244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 250232 KB Output is correct
2 Correct 214 ms 250200 KB Output is correct
3 Correct 214 ms 250232 KB Output is correct
4 Correct 214 ms 250232 KB Output is correct
5 Correct 222 ms 250232 KB Output is correct
6 Correct 214 ms 250208 KB Output is correct
7 Correct 216 ms 250360 KB Output is correct
8 Correct 213 ms 250220 KB Output is correct
9 Correct 213 ms 250228 KB Output is correct
10 Correct 215 ms 250288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 250364 KB Output is correct
2 Correct 211 ms 250232 KB Output is correct
3 Correct 212 ms 250232 KB Output is correct
4 Correct 213 ms 250204 KB Output is correct
5 Correct 212 ms 250232 KB Output is correct
6 Correct 213 ms 250232 KB Output is correct
7 Correct 212 ms 250460 KB Output is correct
8 Correct 213 ms 250332 KB Output is correct
9 Correct 212 ms 250232 KB Output is correct
10 Correct 215 ms 250244 KB Output is correct
11 Correct 213 ms 250232 KB Output is correct
12 Correct 214 ms 250200 KB Output is correct
13 Correct 214 ms 250232 KB Output is correct
14 Correct 214 ms 250232 KB Output is correct
15 Correct 222 ms 250232 KB Output is correct
16 Correct 214 ms 250208 KB Output is correct
17 Correct 216 ms 250360 KB Output is correct
18 Correct 213 ms 250220 KB Output is correct
19 Correct 213 ms 250228 KB Output is correct
20 Correct 215 ms 250288 KB Output is correct
21 Correct 214 ms 250244 KB Output is correct
22 Correct 336 ms 250244 KB Output is correct
23 Correct 269 ms 250308 KB Output is correct
24 Correct 282 ms 250360 KB Output is correct
25 Correct 266 ms 250360 KB Output is correct
26 Correct 257 ms 250276 KB Output is correct
27 Correct 240 ms 250280 KB Output is correct
28 Correct 254 ms 250280 KB Output is correct
29 Correct 296 ms 250360 KB Output is correct
30 Correct 270 ms 250232 KB Output is correct