Submission #573782

# Submission time Handle Problem Language Result Execution time Memory
573782 2022-06-07T07:56:04 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;

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) {
        auto _g = _f;
        auto g = _g.data() + lim;
        auto tr = [&](int x) {
            for (int j = -lim; j <= lim; j++) {
                if (j + i * x >= -lim && j + i * x <= lim) {
                    if (g[j + i * x] < g[j] + x) g[j + i * x] = g[j] + x;
                }
            }
        };
        a[i] = min(a[i], 2LL * lim / abs(i));
        for (int j = 20; j; j--) if ((1 << j) - 1 <= a[i]) {
            for (int k = 0; k < j; k++) tr(1 << k);
            tr(a[i] - (1 << j) + 1); break;
        }
        _g = _f, g = _g.data() + lim, _f = _g;
        b[i] = min(b[i], 2LL * lim / abs(i));
        for (int j = 20; j; j--) if ((1 << j) - 1 <= b[i]) {
            for (int k = 0; k < j; k++) tr(-1 << k);
            tr(-(b[i] - (1 << j) + 1)); break;
        }
        for (int j = -lim; j <= lim; j++) {
            f[j] = max(f[j], g[j]);
        }
    }
    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 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 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 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 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 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 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 -