Submission #573767

# Submission time Handle Problem Language Result Execution time Memory
573767 2022-06-07T07:36:06 Z eecs Uplifting Excursion (BOI22_vault) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

void chk(int &x, int y) {
    if (x < y) x = y;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int m;
    ll L, all = 0;
    cin >> m >> L;
    vector<ll> _a(2 * m + 1), _b(2 * m + 1);
    auto a = _a.data() + m, b = _b.data() + m;
    for (int i = -m; i <= m; i++) {
        cin >> a[i], all += max(0, i) * a[i];
    }
    if (L < 0) {
        L *= -1, all = 0;
        for (int i = 1; i <= m; i++) swap(a[i], a[-i]), all += i * a[i];
    }
    if (all < L) cout << "impossible\n", exit(0);
    ll ans = a[0];
    for (int i = -1; i >= -m; i--) {
        b[i] = min(a[i], (all - L) / -i);
        ans += b[i], L -= b[i] * i, a[i] -= b[i];
    }
    for (int i = 1; i <= m; i++) {
        b[i] = min(a[i], L / i);
        ans += b[i], L -= b[i] * i, a[i] -= b[i];
    }
    int lim = m * L;
    vector<int> _f(2 * lim + 1, -1e9);
    auto f = _f.data() + lim;
    f[0] = 0;
    for (int i = -m; i <= m; i++) if (i) {
        vector<int> _g(2 * lim + 1, -1e9);
        auto g = _g.data() + lim;
        auto tr = [&](int x, int w) {
            for (int j = -lim; j <= lim; j++) {
                if (j + x >= -lim && j + x <= lim) chk(g[j + x], f[j] + w);
            }
        };
        a[i] = min(a[i], 2LL * lim / i), b[i] = min(b[i], 2LL * lim / i);
        for (int j = 20; ~j; j--) {
            if (a[i] >> j & 1) tr(i * (1 << j), 1 << j);
            if (b[i] >> j & 1) tr(-i * (1 << j), -(1 << j));
        }
        swap(_f, _g);
    }
    if (f[L] < -1e8) cout << "impossible\n";
    else cout << ans + f[L] << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -