Submission #721859

# Submission time Handle Problem Language Result Execution time Memory
721859 2023-04-11T07:59:04 Z OttincaM Uplifting Excursion (BOI22_vault) C++17
0 / 100
412 ms 524288 KB
#include <iostream>
#include <vector>
#include "stdio.h"
using namespace std;
#define int long long
 
long long const LLINF = 8e18;
int const N = 600000;
int const ZER = 300000;
 
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    #ifdef WTF
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt", "w", stderr);
    #endif
 
 
    int m, l; cin >> m >> l;
    int smn = 0, smf = 0;
    vector <int> a(2 * m + 2), x, y, z;
    for(int i = 1; i <= 2 * m + 1; i ++){
         cin >> a[i];
         int K = a[i];
         while(K --){
            if(i - 1 - m > 0){
                x.push_back(i - 1 - m);
                smn += i - 1 - m;
            } else if(i - 1 - m < 0){
                y.push_back(i - 1 - m);
                smf += i - 1 - m;
            } else {
                z.push_back(i - 1 - m);
            }
         }
    }
    if(l > smn || l < smf){
        cout << "impossible\n"; return 0;
    }

    vector <int> dp(N, -LLINF);
    dp[ZER] = (int)z.size();
    vector <int> id;
    id.push_back(ZER);

    for(int t: x){
        vector <int> nw;
        for(int i: id){
            if(i + t < N){
                if(dp[i + t] == -LLINF) nw.push_back(i + t);
                dp[i + t] = max(dp[i + t], dp[i] + 1);
            }
        }
        for(int i: nw) id.push_back(i);
    }
 
    for(int t: y){
        vector <int> nw;
        for(int i: id){
            if(i + t >= 0){
                if(dp[i + t] == -LLINF) nw.push_back(i + t);
                dp[i + t] = max(dp[i + t], dp[i] + 1);
            }
        }
        for(int i: nw) id.push_back(i);
    }
        // for(int i = 0; i < N; i ++) cout << dp[i] << " ";
 
    int ans = -LLINF;
    for(int i = 0; i < N; i ++){
        if(i - ZER == l){
            ans = dp[i]; break;
        }
    }
 
    if(ans == -LLINF){
        cout << "impossible\n";
    } else {
        cout << ans << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 348 ms 6120 KB Output is correct
7 Correct 61 ms 5360 KB Output is correct
8 Incorrect 343 ms 5604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 348 ms 6120 KB Output is correct
7 Correct 61 ms 5360 KB Output is correct
8 Incorrect 343 ms 5604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Runtime error 412 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Runtime error 412 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Runtime error 412 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 348 ms 6120 KB Output is correct
7 Correct 61 ms 5360 KB Output is correct
8 Incorrect 343 ms 5604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Runtime error 412 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 348 ms 6120 KB Output is correct
7 Correct 61 ms 5360 KB Output is correct
8 Incorrect 343 ms 5604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Runtime error 412 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 348 ms 6120 KB Output is correct
7 Correct 61 ms 5360 KB Output is correct
8 Incorrect 343 ms 5604 KB Output isn't correct
9 Halted 0 ms 0 KB -