Submission #927234

# Submission time Handle Problem Language Result Execution time Memory
927234 2024-02-14T13:38:14 Z math_rabbit_1028 Uplifting Excursion (BOI22_vault) C++14
0 / 100
59 ms 80472 KB
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

int M;
ll L, S, arr[1010], rem[1010], ans;

ll dp[660][101010];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> M >> L;
    for (int i = 0; i <= 2*M; i++) cin >> arr[i];
    for (int i = 0; i <= 2*M; i++) S += (i-M)*arr[i];
    if (S < L) {
        L = -L;
        for (int i = 0; i <= M; i++) swap(arr[i], arr[2*M-i]);
    }

    S = 0;
    for (int i = 0; i <= M; i++) {
        S += (i-M)*arr[i];
        ans += arr[i];
        rem[2*M-i] = arr[i];
        arr[i] = 0;
    }
    if (S > L) {
        cout << "impossible\n";
        return 0;
    }
    for (int i = M+1; i <= 2*M; i++) {
        ll t = (L-S)/(i-M);
        if (t >= arr[i]) {
            ans += arr[i];
            rem[2*M-i] = arr[i];
            S += arr[i]*(i-M);
            arr[i] = 0;
        }
        else {
            ans += t;
            rem[2*M-i] = t;
            S += t*(i-M);
            arr[i] -= t;
            break;
        }
    }

    for (int j = 0; j <= 2*M*M; j++) dp[0][j] = -1e18;
    dp[0][M*M] = 0;
    for (int i = 1; i <= M; i++) {
        for (int j = 2*M*M; j >= 0; j--) {
            dp[i][j] = -1e18;
            for (int k = 0; k <= arr[M+i]; k++) {
                if (j-i*k < 0) break;
                dp[i][j] = max(dp[i][j], dp[i-1][j-i*k]+k);
            }
            for (int k = 0; k <= rem[M+i]; k++) {
                if (j-i*k < 0) break;
                dp[i][j] = max(dp[i][j], dp[i-1][j-i*k]-k);
            }
        }
        //cout << i << " " << dp[i][L-S+M*M] << "\n";
    }
    for (int i = M+1; i <= 2*M; i++) {
        for (int j = 0; j <= 2*M*M; j++) {
            dp[i][j] = -1e18;
            for (int k = 0; k <= arr[2*M-i]; k++) {
                if (j+i*k < 0) break;
                dp[i][j] = max(dp[i][j], dp[i-1][j+(i-M)*k]+k);
            }
            for (int k = 0; k <= rem[2*M-i]; k++) {
                if (j+i*k < 0) break;
                dp[i][j] = max(dp[i][j], dp[i-1][j+(i-M)*k]-k);
            }
        }
        //cout << i << " " << dp[i][L-S+M*M] << "\n";
    }

    if (dp[2*M][L-S+M*M] <= -1e18) cout << "impossible\n";
    else cout << ans + dp[2*M][L-S+M*M] << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 28 ms 80428 KB Output is correct
7 Incorrect 14 ms 80472 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 28 ms 80428 KB Output is correct
7 Incorrect 14 ms 80472 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Runtime error 59 ms 55376 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Runtime error 59 ms 55376 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Runtime error 59 ms 55376 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 28 ms 80428 KB Output is correct
7 Incorrect 14 ms 80472 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Runtime error 59 ms 55376 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 28 ms 80428 KB Output is correct
7 Incorrect 14 ms 80472 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Runtime error 59 ms 55376 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 28 ms 80428 KB Output is correct
7 Incorrect 14 ms 80472 KB Output isn't correct
8 Halted 0 ms 0 KB -