Submission #721667

# Submission time Handle Problem Language Result Execution time Memory
721667 2023-04-11T06:25:05 Z The_Samurai Uplifting Excursion (BOI22_vault) C++17
20 / 100
84 ms 4324 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int INF = 1e9;

void solve() {
    int n, zero = 0;
    ll l;
    cin >> n >> l;
    vector<ll> a(n + 1), b(n + 1);
    for (int i = 0; i < n; i++)
        cin >> b[n - i];
    cin >> zero;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    if (l < 0) {
        swap(a, b);
        l = -l;
    }
    if (*max_element(a.begin(), a.end()) <= 100) {
        int N = 5e5 + 1e4, ans = 0;
        vector<int> dp_plus(N, -INF), dp_minus(N, -INF);
        dp_plus[0] = dp_minus[0] = 0;
        if (l > N) {
            cout << "impossible";
            return;
        }
        int sum1 = 0, sum2 = 0;
        for (int i = 1; i <= n; i++) {
            sum1 += a[i] * i;
            sum2 += b[i] * i;
            for (int j = sum1; j >= i; j--) {
                for (int k = 1; k <= a[i] and i * k <= j; k++) {
                    if (dp_plus[j - i * k] >= 0) {
                        dp_plus[j] = max(dp_plus[j], dp_plus[j - i * k] + k);
                        break;
                    }
                }
            }
            for (int j = sum2; j >= i; j--) {
                for (int k = 1; k <= b[i] and i * k <= j; k++) {
                    if (dp_minus[j - i * k] >= 0) {
                        dp_minus[j] = max(dp_minus[j], dp_minus[j - i * k] + k);
                        break;
                    }
                }
            }
        }
        for (int i = l; i < N; i++) {
            ans = max(ans, dp_plus[i] + dp_minus[i - l]);
        }
        if (ans == 0) cout << "impossible";
        else cout << ans + zero;
    }
}

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

    int queries = 1;
#ifdef test_cases
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
//    cin >> queries;
#else
//    cin >> queries;
#endif

    for (int test_case = 1; test_case <= queries; test_case++) {
        solve();
//        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 5 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 5 ms 4308 KB Output is correct
9 Correct 9 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 5 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 5 ms 4308 KB Output is correct
9 Correct 9 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 2 ms 4204 KB Output is correct
16 Correct 2 ms 4308 KB Output is correct
17 Correct 5 ms 4308 KB Output is correct
18 Correct 3 ms 4308 KB Output is correct
19 Correct 5 ms 4324 KB Output is correct
20 Correct 11 ms 4308 KB Output is correct
21 Correct 2 ms 4308 KB Output is correct
22 Correct 2 ms 4308 KB Output is correct
23 Correct 2 ms 4308 KB Output is correct
24 Correct 41 ms 4308 KB Output is correct
25 Correct 18 ms 4308 KB Output is correct
26 Correct 84 ms 4308 KB Output is correct
27 Correct 82 ms 4308 KB Output is correct
28 Correct 4 ms 4308 KB Output is correct
29 Correct 4 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 5 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 5 ms 4308 KB Output is correct
9 Correct 9 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 5 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 5 ms 4308 KB Output is correct
9 Correct 9 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 2 ms 4204 KB Output is correct
16 Correct 2 ms 4308 KB Output is correct
17 Correct 5 ms 4308 KB Output is correct
18 Correct 3 ms 4308 KB Output is correct
19 Correct 5 ms 4324 KB Output is correct
20 Correct 11 ms 4308 KB Output is correct
21 Correct 2 ms 4308 KB Output is correct
22 Correct 2 ms 4308 KB Output is correct
23 Correct 2 ms 4308 KB Output is correct
24 Correct 41 ms 4308 KB Output is correct
25 Correct 18 ms 4308 KB Output is correct
26 Correct 84 ms 4308 KB Output is correct
27 Correct 82 ms 4308 KB Output is correct
28 Correct 4 ms 4308 KB Output is correct
29 Correct 4 ms 4308 KB Output is correct
30 Correct 2 ms 4308 KB Output is correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 5 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 5 ms 4308 KB Output is correct
9 Correct 9 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 2 ms 4204 KB Output is correct
16 Correct 2 ms 4308 KB Output is correct
17 Correct 5 ms 4308 KB Output is correct
18 Correct 3 ms 4308 KB Output is correct
19 Correct 5 ms 4324 KB Output is correct
20 Correct 11 ms 4308 KB Output is correct
21 Correct 2 ms 4308 KB Output is correct
22 Correct 2 ms 4308 KB Output is correct
23 Correct 2 ms 4308 KB Output is correct
24 Correct 41 ms 4308 KB Output is correct
25 Correct 18 ms 4308 KB Output is correct
26 Correct 84 ms 4308 KB Output is correct
27 Correct 82 ms 4308 KB Output is correct
28 Correct 4 ms 4308 KB Output is correct
29 Correct 4 ms 4308 KB Output is correct
30 Correct 2 ms 4308 KB Output is correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -