답안 #951897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
951897 2024-03-22T22:14:12 Z vjudge1 Skyscraper (JOI16_skyscraper) C++17
100 / 100
192 ms 347328 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

using LL = long long;
using PII = pair <int, int>;

mt19937_64 rnd(chrono :: steady_clock :: now().time_since_epoch().count());

#ifdef LEL
#include "dbg.h"
#else
#define dbg(...) {/*temon kichu na*/}
#endif
/*....................................................................*/ 

const LL MOD = 1e9 + 7;

const int N = 105, L = 1005;
LL dp[N][N][L][2][2], h[N];

void add(LL &x, LL y) {
    x += y;
    x -= MOD * (x >= MOD);
}
LL mul(LL x, LL y) {
    return x * y % MOD;
}

LL call(int n, int k, int l, int st, int en) {
    LL inc = h[n + 1] - h[n], ends = 2 * k - st - en;
    l -= ends * inc;
    if(l < 0 or k < 0) return 0;
    if(n > 0 and k == 1 and st and en) return 0;
    if(n < 1) return (k == 1 and st and en);

    LL &ret = dp[n][k][l][st][en];
    if(ret != -1) return ret;

    ret = 0;

    add(ret, mul(ends, call(n - 1, k, l, st, en)));
    if(!st) add(ret, mul(k - (en and k > 1), call(n - 1, k, l, 1, en)));
    if(!en) add(ret, mul(k - (st and k > 1), call(n - 1, k, l, st, 1)));

    add(ret, call(n - 1, k + 1, l, st, en));
    if(!st) add(ret, call(n - 1, k + 1, l, 1, en));
    if(!en) add(ret, call(n - 1, k + 1, l, st, 1));

    LL comb = mul(k - 1, k - st - en);
    if(st and en and k == 2) add(comb, 1);

    if(k > 1) add(ret, mul(comb, call(n - 1, k - 1, l, st, en)));

    return ret;
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    int n, l;
    cin >> n >> l;
    for(int i = 1; i <= n; i++) cin >> h[i];
    sort(h + 1, h + n + 1);
    h[n + 1] = h[n];

    if(n == 1) cout << 1 << '\n';
    else {
        memset(dp, -1, sizeof dp);
        LL ans = call(n - 1, 1, l, 0, 0);
        add(ans, call(n - 1, 1, l, 0, 1));
        add(ans, call(n - 1, 1, l, 1, 0));
        cout << ans << '\n';
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 70 ms 347288 KB Output is correct
3 Correct 71 ms 347256 KB Output is correct
4 Correct 71 ms 347216 KB Output is correct
5 Correct 71 ms 347292 KB Output is correct
6 Correct 70 ms 347220 KB Output is correct
7 Correct 71 ms 347196 KB Output is correct
8 Correct 69 ms 347216 KB Output is correct
9 Correct 69 ms 347216 KB Output is correct
10 Correct 95 ms 347272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 347220 KB Output is correct
2 Correct 71 ms 347192 KB Output is correct
3 Correct 71 ms 347216 KB Output is correct
4 Correct 71 ms 347220 KB Output is correct
5 Correct 77 ms 347308 KB Output is correct
6 Correct 71 ms 347220 KB Output is correct
7 Correct 71 ms 347268 KB Output is correct
8 Correct 73 ms 347216 KB Output is correct
9 Correct 71 ms 347220 KB Output is correct
10 Correct 71 ms 347304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 70 ms 347288 KB Output is correct
3 Correct 71 ms 347256 KB Output is correct
4 Correct 71 ms 347216 KB Output is correct
5 Correct 71 ms 347292 KB Output is correct
6 Correct 70 ms 347220 KB Output is correct
7 Correct 71 ms 347196 KB Output is correct
8 Correct 69 ms 347216 KB Output is correct
9 Correct 69 ms 347216 KB Output is correct
10 Correct 95 ms 347272 KB Output is correct
11 Correct 69 ms 347220 KB Output is correct
12 Correct 71 ms 347192 KB Output is correct
13 Correct 71 ms 347216 KB Output is correct
14 Correct 71 ms 347220 KB Output is correct
15 Correct 77 ms 347308 KB Output is correct
16 Correct 71 ms 347220 KB Output is correct
17 Correct 71 ms 347268 KB Output is correct
18 Correct 73 ms 347216 KB Output is correct
19 Correct 71 ms 347220 KB Output is correct
20 Correct 71 ms 347304 KB Output is correct
21 Correct 69 ms 347216 KB Output is correct
22 Correct 192 ms 347216 KB Output is correct
23 Correct 108 ms 347220 KB Output is correct
24 Correct 117 ms 347328 KB Output is correct
25 Correct 103 ms 347216 KB Output is correct
26 Correct 99 ms 347220 KB Output is correct
27 Correct 93 ms 347216 KB Output is correct
28 Correct 110 ms 347216 KB Output is correct
29 Correct 165 ms 347220 KB Output is correct
30 Correct 107 ms 347136 KB Output is correct