Submission #721759

# Submission time Handle Problem Language Result Execution time Memory
721759 2023-04-11T07:05:31 Z dxz05 Uplifting Excursion (BOI22_vault) C++17
0 / 100
2 ms 340 KB
#pragma GCC optimize("Ofast,O3,unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 100500;

long long solve(){
    int m; ll L;
    cin >> m >> L;

    if (L < 0) return -1;

    vector<ll> a(m + 1);
    vector<int> b;
    for (int i = -m; i <= m; i++){
        ll x;
        cin >> x;
        if (i < 0) continue;
        a[i] = x;

        if (i > 0) {
            ll mn = min((ll) 10 * m / i, a[i]);
            while (mn--) b.push_back(i);
        }
    }

    const int LIM = accumulate(all(b), 0) + 1;

    vector<int> dp(LIM, 1e9);
    dp[0] = 0;
    for (int x : b) {
        for (int i = LIM - 1; i >= x; i--) {
            dp[i] = min(dp[i], dp[i - x] + 1);
        }
    }

    if (L == 0) return a[0];
    if (L >= LIM) return -1;

    ll ans = -1;

    ll tot = 0, cnt = a[0];
    for (int v = 1; v <= m; v++){
        assert(tot <= L);

        ll x = min(a[v], (L - tot) / v);
        tot += x * v;
        cnt += x;

        if (tot == L){
            ans = max(ans, cnt);
        } else if (a[v] > x){
            int add = 0;
            for (ll del = tot + v - L; del < LIM; del += v){
                add++;
                if (add <= a[v] - x) ans = max(ans, cnt - dp[del] + add);
            }
        }

    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    long long result = solve();

    if (result != -1){
        cout << result << endl;
    } else {
        cout << "impossible" << endl;
    }

    return 0;
}
# 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 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 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 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 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 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 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 -