Submission #721670

# Submission time Handle Problem Language Result Execution time Memory
721670 2023-04-11T06:27:07 Z dxz05 Uplifting Excursion (BOI22_vault) C++17
20 / 100
2666 ms 4424 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;

const int LIM = 100 * 100 * 101 / 2 + 1;

vector<int> knapsack(vector<int> a){
    vector<int> dp(LIM, -1e9);
    dp[0] = 0;

    for (int x : a) {
        for (int i = LIM - 1; i >= x; i--) {
            dp[i] = max(dp[i], dp[i - x] + 1);
        }
    }

    return dp;
}

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

    if (L >= LIM || L <= -LIM){
        cout << "impossible" << endl;
        return;
    }

    vector<int> pos, neg;
    for (int i = -m; i <= m; i++){
        int x;
        cin >> x;
        while (x--){
            if (i >= 0){
                pos.push_back(i);
            } else {
                neg.push_back(-i);
            }
        }
    }

    vector<int> dp1 = knapsack(pos);
    vector<int> dp2 = knapsack(neg);

    if (L < 0){
        L = -L;
        swap(dp1, dp2);
    }

    int ans = -1e9;
    for (int x = L; x < LIM; x++) {
        int y = x - L;
        ans = max(ans, dp1[x] + dp2[y]);
    }

    if (ans < 0) {
        cout << "impossible" << endl;
    } else {
        cout << ans << endl;
    }
}

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

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

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4180 KB Output is correct
2 Correct 4 ms 4180 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 11 ms 4180 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 372 ms 4292 KB Output is correct
7 Correct 154 ms 4280 KB Output is correct
8 Correct 372 ms 4232 KB Output is correct
9 Correct 649 ms 4248 KB Output is correct
10 Correct 21 ms 4180 KB Output is correct
11 Correct 16 ms 4228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4180 KB Output is correct
2 Correct 4 ms 4180 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 11 ms 4180 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 372 ms 4292 KB Output is correct
7 Correct 154 ms 4280 KB Output is correct
8 Correct 372 ms 4232 KB Output is correct
9 Correct 649 ms 4248 KB Output is correct
10 Correct 21 ms 4180 KB Output is correct
11 Correct 16 ms 4228 KB Output is correct
12 Correct 4 ms 4180 KB Output is correct
13 Correct 4 ms 4180 KB Output is correct
14 Correct 4 ms 4180 KB Output is correct
15 Correct 13 ms 4220 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 365 ms 4296 KB Output is correct
18 Correct 159 ms 4224 KB Output is correct
19 Correct 360 ms 4292 KB Output is correct
20 Correct 687 ms 4304 KB Output is correct
21 Correct 16 ms 4180 KB Output is correct
22 Correct 16 ms 4228 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1342 ms 4292 KB Output is correct
25 Correct 484 ms 4304 KB Output is correct
26 Correct 2666 ms 4424 KB Output is correct
27 Correct 2647 ms 4424 KB Output is correct
28 Correct 45 ms 4228 KB Output is correct
29 Correct 31 ms 4220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4180 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4180 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4180 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4180 KB Output is correct
2 Correct 4 ms 4180 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 11 ms 4180 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 372 ms 4292 KB Output is correct
7 Correct 154 ms 4280 KB Output is correct
8 Correct 372 ms 4232 KB Output is correct
9 Correct 649 ms 4248 KB Output is correct
10 Correct 21 ms 4180 KB Output is correct
11 Correct 16 ms 4228 KB Output is correct
12 Correct 11 ms 4180 KB Output is correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4180 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4180 KB Output is correct
2 Correct 4 ms 4180 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 11 ms 4180 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 372 ms 4292 KB Output is correct
7 Correct 154 ms 4280 KB Output is correct
8 Correct 372 ms 4232 KB Output is correct
9 Correct 649 ms 4248 KB Output is correct
10 Correct 21 ms 4180 KB Output is correct
11 Correct 16 ms 4228 KB Output is correct
12 Correct 4 ms 4180 KB Output is correct
13 Correct 4 ms 4180 KB Output is correct
14 Correct 4 ms 4180 KB Output is correct
15 Correct 13 ms 4220 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 365 ms 4296 KB Output is correct
18 Correct 159 ms 4224 KB Output is correct
19 Correct 360 ms 4292 KB Output is correct
20 Correct 687 ms 4304 KB Output is correct
21 Correct 16 ms 4180 KB Output is correct
22 Correct 16 ms 4228 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1342 ms 4292 KB Output is correct
25 Correct 484 ms 4304 KB Output is correct
26 Correct 2666 ms 4424 KB Output is correct
27 Correct 2647 ms 4424 KB Output is correct
28 Correct 45 ms 4228 KB Output is correct
29 Correct 31 ms 4220 KB Output is correct
30 Correct 11 ms 4180 KB Output is correct
31 Incorrect 1 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4180 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4180 KB Output is correct
2 Correct 4 ms 4180 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 11 ms 4180 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 372 ms 4292 KB Output is correct
7 Correct 154 ms 4280 KB Output is correct
8 Correct 372 ms 4232 KB Output is correct
9 Correct 649 ms 4248 KB Output is correct
10 Correct 21 ms 4180 KB Output is correct
11 Correct 16 ms 4228 KB Output is correct
12 Correct 4 ms 4180 KB Output is correct
13 Correct 4 ms 4180 KB Output is correct
14 Correct 4 ms 4180 KB Output is correct
15 Correct 13 ms 4220 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 365 ms 4296 KB Output is correct
18 Correct 159 ms 4224 KB Output is correct
19 Correct 360 ms 4292 KB Output is correct
20 Correct 687 ms 4304 KB Output is correct
21 Correct 16 ms 4180 KB Output is correct
22 Correct 16 ms 4228 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1342 ms 4292 KB Output is correct
25 Correct 484 ms 4304 KB Output is correct
26 Correct 2666 ms 4424 KB Output is correct
27 Correct 2647 ms 4424 KB Output is correct
28 Correct 45 ms 4228 KB Output is correct
29 Correct 31 ms 4220 KB Output is correct
30 Correct 11 ms 4180 KB Output is correct
31 Incorrect 1 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -