Submission #572994

# Submission time Handle Problem Language Result Execution time Memory
572994 2022-06-05T15:27:03 Z MohamedFaresNebili Uplifting Excursion (BOI22_vault) C++14
0 / 100
5000 ms 52012 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

        using namespace std;
        using namespace __gnu_pbds;

        using ll = long long;
        using ii = pair<int, int>;
        using vi = vector<int>;

        #define pb push_back
        #define pp pop_back
        #define ff first
        #define ss second
        #define lb lower_bound

        typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;

        const int oo = 1e9 + 7;

        int N, M, A[1000];
        map<pair<ii, int>, int> DP;
        int solve(int i, int curr, int state) {
            if(i == 2 * N + 1) {
                if(state == M) return curr;
                return -oo;
            }
            if(DP.count({{i, state}, curr}))
                return DP[{{i, state}, curr}];
            int best = -oo;
            for(int l = 0; l <= A[i]; l++)
                best = max(best,
                    solve(i + 1, curr + l, state + l * (i - N)));
            return DP[{{i, state}, curr}] = best;
        }

        int32_t main() {
            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            cin >> N >> M;
            for(int l = 0; l <= 2 * N; l++) cin >> A[l];
            int ans = solve(0, 0, 0);
            if(ans == -oo) cout << "impossible\n";
            else cout << ans << "\n";
        }


























# Verdict Execution time Memory Grader output
1 Correct 0 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 16 ms 1364 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Execution timed out 5053 ms 52012 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 16 ms 1364 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Execution timed out 5053 ms 52012 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1364 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 16 ms 1364 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 16 ms 1364 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 0 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 16 ms 1364 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Execution timed out 5053 ms 52012 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1364 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 0 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 16 ms 1364 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Execution timed out 5053 ms 52012 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1364 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 0 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 16 ms 1364 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Execution timed out 5053 ms 52012 KB Time limit exceeded
7 Halted 0 ms 0 KB -