Submission #876810

# Submission time Handle Problem Language Result Execution time Memory
876810 2023-11-22T11:16:55 Z vjudge1 Skyscraper (JOI16_skyscraper) C++17
5 / 100
17 ms 37216 KB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int n, L;
vector<int> v;
ll dp[1<<8][9][1005];

ll f(int mask, int last, int total) {
    if(total > L) return 0;
    if(__builtin_popcount(mask) == n) return 1;
    if(dp[mask][last][total] != -1) return dp[mask][last][total];

    ll ans = 0;
    for(int i=0; i<n; i++) {
        if(mask & (1 << i)) continue;
        int newTotal = total + (last == 8 ? 0 : abs(v[i] - v[last]));
        ans += f(mask | (1 << i), i, newTotal);
    }

    return dp[mask][last][total] = ans;
}

int32_t main() {
    setIO();
    memset(dp, -1, sizeof(dp));

    cin >> n >> L;
    v.resize(n);
    for(int &x : v) cin >> x;

    cout << f(0, 8, 0) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18520 KB Output is correct
2 Correct 3 ms 18524 KB Output is correct
3 Correct 3 ms 18524 KB Output is correct
4 Correct 3 ms 18524 KB Output is correct
5 Correct 3 ms 18524 KB Output is correct
6 Correct 3 ms 18524 KB Output is correct
7 Correct 3 ms 18524 KB Output is correct
8 Correct 4 ms 18580 KB Output is correct
9 Correct 3 ms 18524 KB Output is correct
10 Correct 3 ms 18524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 37216 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18520 KB Output is correct
2 Correct 3 ms 18524 KB Output is correct
3 Correct 3 ms 18524 KB Output is correct
4 Correct 3 ms 18524 KB Output is correct
5 Correct 3 ms 18524 KB Output is correct
6 Correct 3 ms 18524 KB Output is correct
7 Correct 3 ms 18524 KB Output is correct
8 Correct 4 ms 18580 KB Output is correct
9 Correct 3 ms 18524 KB Output is correct
10 Correct 3 ms 18524 KB Output is correct
11 Runtime error 17 ms 37216 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -