Submission #386162

# Submission time Handle Problem Language Result Execution time Memory
386162 2021-04-05T20:45:51 Z Vladth11 Skyscraper (JOI16_skyscraper) C++14
100 / 100
585 ms 320236 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 > 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];
    }
    if(pz == n) {
        ll sol = 0;
        if(st == 0 && dr == 0) {
            return dp[pz][score][components][st][dr] = 0;
        }
        if(components == 1) {
            if(st == 0) {
                sol++;
            }
            if(dr == 0) {
                sol++;
            }
            return dp[pz][score][components][st][dr] = sol;
        }
        if(components == 2) {
            if(st + dr != 2) {
                return dp[pz][score][components][st][dr] = sol;
            }
            sol++;
            return dp[pz][score][components][st][dr] = sol;
        }
        return 0;
    }
    ll sol = 0;
    ///1. v[pz] il punem ca st
    if(st != 1) {
       
        ///propria componenta
        add(sol, Compute(pz + 1, score, components + 1, 1, dr));
        ///la ce mai din stanga componenta 
     if(!(dr == 1 && components == 1)){
        if(components > 0)
            add(sol, Compute(pz + 1, score, components, 1, dr));
        }
    }
    if(dr != 1) {
       
            add(sol, Compute(pz + 1, score, components + 1, st, 1));
      if(!(st == 1 && components == 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;
}
# Verdict Execution time Memory Grader output
1 Correct 156 ms 320236 KB Output is correct
2 Correct 153 ms 319980 KB Output is correct
3 Correct 152 ms 320128 KB Output is correct
4 Correct 155 ms 320040 KB Output is correct
5 Correct 153 ms 320020 KB Output is correct
6 Correct 152 ms 320108 KB Output is correct
7 Correct 152 ms 320004 KB Output is correct
8 Correct 157 ms 320072 KB Output is correct
9 Correct 157 ms 319980 KB Output is correct
10 Correct 157 ms 320084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 319980 KB Output is correct
2 Correct 152 ms 320108 KB Output is correct
3 Correct 165 ms 320108 KB Output is correct
4 Correct 155 ms 319980 KB Output is correct
5 Correct 153 ms 319980 KB Output is correct
6 Correct 153 ms 320108 KB Output is correct
7 Correct 158 ms 319980 KB Output is correct
8 Correct 155 ms 320108 KB Output is correct
9 Correct 154 ms 319980 KB Output is correct
10 Correct 155 ms 319980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 320236 KB Output is correct
2 Correct 153 ms 319980 KB Output is correct
3 Correct 152 ms 320128 KB Output is correct
4 Correct 155 ms 320040 KB Output is correct
5 Correct 153 ms 320020 KB Output is correct
6 Correct 152 ms 320108 KB Output is correct
7 Correct 152 ms 320004 KB Output is correct
8 Correct 157 ms 320072 KB Output is correct
9 Correct 157 ms 319980 KB Output is correct
10 Correct 157 ms 320084 KB Output is correct
11 Correct 158 ms 319980 KB Output is correct
12 Correct 152 ms 320108 KB Output is correct
13 Correct 165 ms 320108 KB Output is correct
14 Correct 155 ms 319980 KB Output is correct
15 Correct 153 ms 319980 KB Output is correct
16 Correct 153 ms 320108 KB Output is correct
17 Correct 158 ms 319980 KB Output is correct
18 Correct 155 ms 320108 KB Output is correct
19 Correct 154 ms 319980 KB Output is correct
20 Correct 155 ms 319980 KB Output is correct
21 Correct 154 ms 320108 KB Output is correct
22 Correct 585 ms 319980 KB Output is correct
23 Correct 339 ms 320108 KB Output is correct
24 Correct 362 ms 320080 KB Output is correct
25 Correct 348 ms 319980 KB Output is correct
26 Correct 330 ms 319980 KB Output is correct
27 Correct 241 ms 319980 KB Output is correct
28 Correct 281 ms 319980 KB Output is correct
29 Correct 424 ms 320108 KB Output is correct
30 Correct 352 ms 320112 KB Output is correct