# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
839811 | nonono | Bootfall (IZhO17_bootfall) | C++14 | 1 ms | 360 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;
const int mxN = 505;
int n, a[mxN];
int sum = 0;
int dp[mxN * mxN];
bool good[mxN * mxN];
void add(int x) {
sum += x;
for(int i = sum; i >= x; i --) dp[i] += dp[i - x];
}
void del(int x) {
for(int i = x; i <= sum; i ++) dp[i] -= dp[i - x];
sum -= x;
}
signed main() {
#define taskname ""
if(fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
cin >> n;
dp[0] = 1;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
add(a[i]);
}
if(sum % 2 || !dp[sum / 2]) {
return cout << 0 << "\n", 0;
}
for(int i = 1; i <= sum; i ++) good[i] = true;
for(int i = 1; i <= n; i ++) {
del(a[i]);
for(int j = 1; j <= sum + a[i]; j ++) {
good[j] = (good[j] && (sum + j) % 2 == 0 && (dp[(sum + j) / 2] > 0));
}
add(a[i]);
}
vector<int> choose;
for(int i = 1; i <= sum; i ++) if(good[i]) choose.push_back(i);
cout << choose.size() << "\n";
for(int x : choose) cout << x << " ";
return 0;
}
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... |