# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344238 | Enkhmunkh | Bootfall (IZhO17_bootfall) | C++14 | 1082 ms | 492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
bool check(int sum, vector<int>v, int n) {
if(sum % 2) {
return 0;
}
sum /= 2;
vector<bool> dp(sum + 1, 0);
dp[0] = 1;
for(int i = 0; i < n; i++) {
for(int j = sum; j >= v[i]; j--) {
if(dp[j - v[i]]) dp[j] = 1;
}
}
if (dp[sum]) {
return 1;
}else {
return 0;
}
}
int main () {
int n;
cin >> n;
vector<int> arr;
int sum = 0;
int tmp;
for (int i = 0; i < n; i++) {
cin >> tmp;
arr.push_back(tmp);
sum+=tmp;
}
vector<int> val;
for (int i = 1; i <= sum; i++) {
vector<int> cp;
sum+=i;
for (int j = 0; j < n; j++) {
cp.push_back(arr[j]);
}
cp.push_back(i);
int b = 0;
for (int j = 0; j < n+1; j++) {
int tmp = cp[j];
sum-=tmp;
cp.erase(cp.begin()+j);
if (check(sum, cp, n)) {
b++;
}
cp.insert(cp.begin() + j, tmp);
sum+=tmp;
}
if (b == n+1) {
val.push_back(i);
}
cp.pop_back();
sum-=i;
}
cout << val.size() << "\n";
for (int i = 0; i < val.size(); i++) {
cout << val[i] << " ";
}
cout << "\n";
}
Compilation message (stderr)
# | 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... |