이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |