Submission #573776

# Submission time Handle Problem Language Result Execution time Memory
573776 2022-06-07T07:48:50 Z eecs Uplifting Excursion (BOI22_vault) C++17
0 / 100
4 ms 340 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, int w) {
            for (int j = -lim; j <= lim; j++) if (j + x >= -lim && j + x <= lim) {
                if (g[j + x] < f[j] + w) g[j + x] = f[j] + w;
            }
        };
        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(i * (1 << k), 1 << k);
            a[i] -= (1 << j) - 1, tr(i * a[i], a[i]); break;
        }
        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(-i * (1 << k), -1 << k);
            b[i] -= (1 << j) - 1, tr(-i * b[i], -b[i]); break;
        }
        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 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 4 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 4 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 4 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 4 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 4 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -