Submission #599214

# Submission time Handle Problem Language Result Execution time Memory
599214 2022-07-19T11:42:35 Z SlavicG Uplifting Excursion (BOI22_vault) C++17
5 / 100
5000 ms 524288 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

vector<int> calc(vector<int> x) {
    int S = accumulate(x.begin(), x.end(), 0);
    vector<int> dp(S + 1, INT_MIN);
    dp[0] = 0;
    for(int i = 0; i < (int)x.size(); ++i) {
        for(int j = S; j >= 0; --j) {
            if(j - x[i] >= 0) if(dp[j - x[i]] != INT_MIN) dp[j] = max(dp[j], dp[j - x[i]] + 1);
        }
    }
    return dp;
}
int main() {
    ll l, m; cin >> m >> l;
    vector<int> a(2 * m + 1);
    for(int i = 0; i < 2 * m + 1; ++i) cin >> a[i];

    int ans = INT_MIN;
    vector<int> neg;
    int val = m;
    for(int i = 0; i < m; ++i) {
        for(int j = 0; j < a[i]; ++j) neg.push_back(val);
        --val;
    }
    vector<int> pos;
    val = 1;
    for(int i = m + 1; i < 2 * m + 1; ++i) {
        for(int j = 0; j < a[i]; ++j) pos.push_back(val);
        ++val;
    }
    vector<int> pp = calc(pos);
    vector<int> ng = calc(neg);

    if(l < 0) {
        swap(pp, ng);
        l = -l;
    }
    for(ll sum = l; sum < (int)pp.size(); ++sum) {
        if(sum - l >= (int)ng.size() || pp[sum] == INT_MIN || ng[sum - l] == INT_MIN) continue;
        ans = max(ans, pp[sum] + ng[sum - l] + a[m]);
    }
    if(ans == INT_MIN) cout << "impossible\n";
    else cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 101 ms 564 KB Output is correct
6 Correct 95 ms 472 KB Output is correct
7 Correct 17 ms 380 KB Output is correct
8 Correct 86 ms 440 KB Output is correct
9 Correct 436 ms 804 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 101 ms 564 KB Output is correct
6 Correct 95 ms 472 KB Output is correct
7 Correct 17 ms 380 KB Output is correct
8 Correct 86 ms 440 KB Output is correct
9 Correct 436 ms 804 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 103 ms 568 KB Output is correct
17 Correct 148 ms 584 KB Output is correct
18 Correct 22 ms 372 KB Output is correct
19 Correct 110 ms 444 KB Output is correct
20 Correct 329 ms 800 KB Output is correct
21 Correct 1 ms 276 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2794 ms 2348 KB Output is correct
24 Correct 2729 ms 2364 KB Output is correct
25 Correct 400 ms 1136 KB Output is correct
26 Execution timed out 5084 ms 2260 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 568 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 568 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 568 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 101 ms 564 KB Output is correct
6 Correct 95 ms 472 KB Output is correct
7 Correct 17 ms 380 KB Output is correct
8 Correct 86 ms 440 KB Output is correct
9 Correct 436 ms 804 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Runtime error 568 ms 524288 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 568 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 101 ms 564 KB Output is correct
6 Correct 95 ms 472 KB Output is correct
7 Correct 17 ms 380 KB Output is correct
8 Correct 86 ms 440 KB Output is correct
9 Correct 436 ms 804 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 103 ms 568 KB Output is correct
17 Correct 148 ms 584 KB Output is correct
18 Correct 22 ms 372 KB Output is correct
19 Correct 110 ms 444 KB Output is correct
20 Correct 329 ms 800 KB Output is correct
21 Correct 1 ms 276 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2794 ms 2348 KB Output is correct
24 Correct 2729 ms 2364 KB Output is correct
25 Correct 400 ms 1136 KB Output is correct
26 Execution timed out 5084 ms 2260 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 568 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 101 ms 564 KB Output is correct
6 Correct 95 ms 472 KB Output is correct
7 Correct 17 ms 380 KB Output is correct
8 Correct 86 ms 440 KB Output is correct
9 Correct 436 ms 804 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 103 ms 568 KB Output is correct
17 Correct 148 ms 584 KB Output is correct
18 Correct 22 ms 372 KB Output is correct
19 Correct 110 ms 444 KB Output is correct
20 Correct 329 ms 800 KB Output is correct
21 Correct 1 ms 276 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2794 ms 2348 KB Output is correct
24 Correct 2729 ms 2364 KB Output is correct
25 Correct 400 ms 1136 KB Output is correct
26 Execution timed out 5084 ms 2260 KB Time limit exceeded
27 Halted 0 ms 0 KB -