Submission #721709

# Submission time Handle Problem Language Result Execution time Memory
721709 2023-04-11T06:45:45 Z dxz05 Uplifting Excursion (BOI22_vault) C++17
0 / 100
1 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) 2 * m / i, a[i]);
            while (mn--) b.push_back(i);
        }
    }

    const int LIM = m * m * (m + 1) / 2;

    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];

    ll ans = -1;

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

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

        if (tot == L){
            ans = max(ans, cnt);
        } else if (a[i] > x){
            ll del = tot + i - L;
            ans = max(ans, cnt - dp[del] + 1);
        }

    }

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