Submission #599204

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

vector<int> calc(vector<int> x) {
    int S = (int)x.size() * 50;
    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 300 KB Output is correct
2 Correct 0 ms 232 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 148 ms 804 KB Output is correct
6 Correct 135 ms 840 KB Output is correct
7 Correct 23 ms 468 KB Output is correct
8 Correct 132 ms 700 KB Output is correct
9 Correct 436 ms 1304 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 300 KB Output is correct
2 Correct 0 ms 232 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 148 ms 804 KB Output is correct
6 Correct 135 ms 840 KB Output is correct
7 Correct 23 ms 468 KB Output is correct
8 Correct 132 ms 700 KB Output is correct
9 Correct 436 ms 1304 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 296 KB Output is correct
13 Correct 1 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 124 ms 812 KB Output is correct
17 Correct 143 ms 844 KB Output is correct
18 Correct 22 ms 440 KB Output is correct
19 Correct 124 ms 700 KB Output is correct
20 Correct 451 ms 1176 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2322 ms 2320 KB Output is correct
24 Incorrect 2198 ms 2324 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 530 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 530 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 530 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 232 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 148 ms 804 KB Output is correct
6 Correct 135 ms 840 KB Output is correct
7 Correct 23 ms 468 KB Output is correct
8 Correct 132 ms 700 KB Output is correct
9 Correct 436 ms 1304 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 530 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 530 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 232 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 148 ms 804 KB Output is correct
6 Correct 135 ms 840 KB Output is correct
7 Correct 23 ms 468 KB Output is correct
8 Correct 132 ms 700 KB Output is correct
9 Correct 436 ms 1304 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 296 KB Output is correct
13 Correct 1 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 124 ms 812 KB Output is correct
17 Correct 143 ms 844 KB Output is correct
18 Correct 22 ms 440 KB Output is correct
19 Correct 124 ms 700 KB Output is correct
20 Correct 451 ms 1176 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2322 ms 2320 KB Output is correct
24 Incorrect 2198 ms 2324 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 530 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 232 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 148 ms 804 KB Output is correct
6 Correct 135 ms 840 KB Output is correct
7 Correct 23 ms 468 KB Output is correct
8 Correct 132 ms 700 KB Output is correct
9 Correct 436 ms 1304 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 296 KB Output is correct
13 Correct 1 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 124 ms 812 KB Output is correct
17 Correct 143 ms 844 KB Output is correct
18 Correct 22 ms 440 KB Output is correct
19 Correct 124 ms 700 KB Output is correct
20 Correct 451 ms 1176 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2322 ms 2320 KB Output is correct
24 Incorrect 2198 ms 2324 KB Output isn't correct
25 Halted 0 ms 0 KB -