Submission #584410

# Submission time Handle Problem Language Result Execution time Memory
584410 2022-06-27T11:11:05 Z drdilyor Skyscraper (JOI16_skyscraper) C++17
15 / 100
747 ms 192756 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
#define allit(a) (a).begin(), (a).end()
#define sz(a) ((int) (a).size())
#define cut(s) {cout << s << '\n'; return 0;}

using namespace std;
using ll = long long;
using vi = vector<int>;
namespace pd = __gnu_pbds;
template<typename K> using ordered_set = pd::tree<K, pd::null_type, less<K>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>;
template<typename... T> using hash_table = pd::gp_hash_table<T...>;

const int INF = 1e9;
const ll INFL = 1e18;
const int N = 14;
const int L = 100;
const int MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);

int solve() {
    int n, l;
    cin >> n >> l;
    vi a(n);
    for (auto& i : a) cin >> i;
    sort(allit(a));

    size_t size = (1<<N) * (N+1) * L+10;
    ll* memo = new ll[size];
    memset(memo, -1, sizeof(ll) * size);

    function<ll(int, int, int)> dp = [&](int used, int l, int prev)->ll {
        int key = (used * N + (prev+1)) * L + l;
        if (memo[key] != -1) return memo[key];
        if (used == (1 << n)-1) return 1;
        ll res = 0;
        for (int i = 0; i < n; i++) {
            if (used & (1<<i)) continue;
            int cost = prev == -1 ? 0 : abs(a[prev] - a[i]);
            if (cost > l) continue;
            res = (res + dp(used | (1 << i), l - cost, i)) % MOD;
        }
        return memo[key] = res;
    };
    cout << dp(0, l, -1);

    return 0;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    //cin >> t;
    while (t-- && cin) {
        if (solve()) break;
        #ifdef ONPC
            cout << "____________________" << endl;
        #endif
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 75 ms 192668 KB Output is correct
2 Correct 74 ms 192732 KB Output is correct
3 Correct 73 ms 192660 KB Output is correct
4 Correct 71 ms 192584 KB Output is correct
5 Correct 72 ms 192672 KB Output is correct
6 Correct 72 ms 192744 KB Output is correct
7 Correct 82 ms 192704 KB Output is correct
8 Correct 77 ms 192644 KB Output is correct
9 Incorrect 71 ms 192648 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 127 ms 192664 KB Output is correct
2 Correct 101 ms 192684 KB Output is correct
3 Correct 500 ms 192756 KB Output is correct
4 Correct 100 ms 192700 KB Output is correct
5 Correct 90 ms 192644 KB Output is correct
6 Correct 463 ms 192604 KB Output is correct
7 Correct 90 ms 192696 KB Output is correct
8 Correct 468 ms 192696 KB Output is correct
9 Correct 747 ms 192696 KB Output is correct
10 Correct 103 ms 192644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 192668 KB Output is correct
2 Correct 74 ms 192732 KB Output is correct
3 Correct 73 ms 192660 KB Output is correct
4 Correct 71 ms 192584 KB Output is correct
5 Correct 72 ms 192672 KB Output is correct
6 Correct 72 ms 192744 KB Output is correct
7 Correct 82 ms 192704 KB Output is correct
8 Correct 77 ms 192644 KB Output is correct
9 Incorrect 71 ms 192648 KB Output isn't correct
10 Halted 0 ms 0 KB -