Submission #963651

#TimeUsernameProblemLanguageResultExecution timeMemory
963651NotLinuxUplifting Excursion (BOI22_vault)C++17
0 / 100
1 ms348 KiB
//author : FatihCihan #include <bits/stdc++.h> using namespace std; #define all(v) v.begin() , v.end() #define sz(a) (int)a.size() const int inf = 1e9 + 7; const int N = 10; void solve(){ int m,l; cin >> m >> l; vector < int > v; for(int i = -m;i<=m;i++){ int x; cin >> x; for(int j = 0;j<x;j++){ v.push_back(i); } } vector < int > knapsack(2 * N + 1 , -inf); knapsack[N] = 0; // for(int i = 0;i<=2*N;i++){ // cout << i - N << " : " << knapsack[i] << endl; // } // cout << endl; for(auto itr : v){ vector < int > newknapsack = knapsack; for(int i = 0;i<=2*N;i++){ newknapsack[i] = max(newknapsack[i] , knapsack[i]); if((i - itr) <= 2*N and (i - itr) >= 0){ newknapsack[i] = max(newknapsack[i] , knapsack[i - itr] + 1); } } swap(knapsack , newknapsack); // for(int i = 0;i<=2*N;i++){ // cout << i - N << " : " << knapsack[i] << endl; // } } // cout << endl; // for(int i = 0;i<=2*N;i++){ // cout << i - N << " : " << knapsack[i] << endl; // } // cout << endl; if(abs(l) <= N){ if(abs(knapsack[l + N]) <= N)cout << knapsack[l + N] << endl; else cout << "impossible" << endl; } else{ cout << "impossible" << endl; } } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); int testcase = 1;//cin >> testcase; while(testcase--)solve(); cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...