답안 #386163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386163 2021-04-05T20:47:38 Z Vladth11 Skyscraper (JOI16_skyscraper) C++14
100 / 100
615 ms 320108 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;

const ll NMAX = 201;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 225;
const ll base = 31;
const ll nr_of_bits = 21;

ll dp[101][1001][101][2][2];
ll n, L;
ll v[101];

void add(ll &x, ll v) {
    x += v;
    x %= MOD;
}

ll Compute(ll pz, ll score, ll components, ll st, ll dr) {
    if(pz == n + 1) {
        return (score <= L && components == 1 && st == 1 && dr == 1);
    }
    if(pz > 1)
        score += (v[pz] - v[pz - 1]) * (2 * components - st - dr);
    if(score > L)
        return 0;
    if(dp[pz][score][components][st][dr] != -1) {
        return dp[pz][score][components][st][dr];
    }
    ll sol = 0;
    ///1. v[pz] il punem ca st
    if(st != 1) {
        //if(!(dr == 1 && components == 1)){
        ///propria componenta
        add(sol, Compute(pz + 1, score, components + 1, 1, dr));
        ///la ce mai din stanga componenta
        if(components > 0)
            add(sol, Compute(pz + 1, score, components, 1, dr));
        //}
    }
    if(dr != 1) {
        //if(!(st == 1 && components == 1)) {
        add(sol, Compute(pz + 1, score, components + 1, st, 1));
        if(components > 0)
            add(sol, Compute(pz + 1, score, components, st, 1));
        // }

    }
    ///o componenta noua
    add(sol, (Compute(pz + 1, score, components + 1, st, dr) * (components + 1 - st - dr)) % MOD);
    ///alipim in stanga unei componente
    if(components > 0)
        add(sol, (Compute(pz + 1, score, components, st, dr) * (components - st)) % MOD);
    ///alipim in dreapta unei componente
    if(components > 0)
        add(sol, (Compute(pz + 1, score, components, st, dr) * (components - dr)) % MOD);
    ///mergeuim doua componente
    if(components > 1)
        add(sol, (Compute(pz + 1, score, components - 1, st, dr) * (components - 1)) % MOD);
    return dp[pz][score][components][st][dr] = sol;
}

int main() {
    memset(dp, -1, sizeof(dp));
    cin >> n >> L;
    if(n == 1) {
        cout << 1;
        return 0;
    }
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    sort(v + 1, v + n + 1);
    cout << Compute(1, 0, 0, 0, 0);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 319980 KB Output is correct
2 Correct 153 ms 319980 KB Output is correct
3 Correct 152 ms 319980 KB Output is correct
4 Correct 155 ms 319980 KB Output is correct
5 Correct 154 ms 319980 KB Output is correct
6 Correct 153 ms 320108 KB Output is correct
7 Correct 153 ms 319980 KB Output is correct
8 Correct 159 ms 320108 KB Output is correct
9 Correct 161 ms 319980 KB Output is correct
10 Correct 154 ms 320108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 319980 KB Output is correct
2 Correct 154 ms 319980 KB Output is correct
3 Correct 153 ms 320108 KB Output is correct
4 Correct 154 ms 319980 KB Output is correct
5 Correct 151 ms 319980 KB Output is correct
6 Correct 153 ms 319980 KB Output is correct
7 Correct 152 ms 320100 KB Output is correct
8 Correct 154 ms 320108 KB Output is correct
9 Correct 153 ms 319980 KB Output is correct
10 Correct 154 ms 319980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 319980 KB Output is correct
2 Correct 153 ms 319980 KB Output is correct
3 Correct 152 ms 319980 KB Output is correct
4 Correct 155 ms 319980 KB Output is correct
5 Correct 154 ms 319980 KB Output is correct
6 Correct 153 ms 320108 KB Output is correct
7 Correct 153 ms 319980 KB Output is correct
8 Correct 159 ms 320108 KB Output is correct
9 Correct 161 ms 319980 KB Output is correct
10 Correct 154 ms 320108 KB Output is correct
11 Correct 154 ms 319980 KB Output is correct
12 Correct 154 ms 319980 KB Output is correct
13 Correct 153 ms 320108 KB Output is correct
14 Correct 154 ms 319980 KB Output is correct
15 Correct 151 ms 319980 KB Output is correct
16 Correct 153 ms 319980 KB Output is correct
17 Correct 152 ms 320100 KB Output is correct
18 Correct 154 ms 320108 KB Output is correct
19 Correct 153 ms 319980 KB Output is correct
20 Correct 154 ms 319980 KB Output is correct
21 Correct 155 ms 319980 KB Output is correct
22 Correct 615 ms 320108 KB Output is correct
23 Correct 333 ms 319980 KB Output is correct
24 Correct 372 ms 319980 KB Output is correct
25 Correct 355 ms 320108 KB Output is correct
26 Correct 313 ms 319980 KB Output is correct
27 Correct 240 ms 319980 KB Output is correct
28 Correct 283 ms 319980 KB Output is correct
29 Correct 432 ms 320108 KB Output is correct
30 Correct 352 ms 319980 KB Output is correct