# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
337573 | boykut | Bootfall (IZhO17_bootfall) | C++14 | 406 ms | 3692 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 MAXN = 500 * 500 + 1;
int dp[MAXN], used[MAXN], a[500], sum;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
dp[0] = 1;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int x = sum; x >= 0; x--) {
dp[x + a[i]] += dp[x];
}
sum += a[i];
}
if (sum % 2 == 1 || dp[sum / 2] == 0) {
cout << "0\n";
} else {
fill (used, used + MAXN, 1);
for (int i = 0; i < n; i++) {
sum -= a[i];
for (int x = 0; x <= sum; x++) {
dp[x + a[i]] -= dp[x];
}
for (int half = 1; half < MAXN; half++) {
if ((sum + half) % 2 == 1 || dp[(sum + half) / 2] == 0)
used[half] = 0;
}
for (int x = sum; x >= 0; x--) {
dp[x + a[i]] += dp[x];
}
sum += a[i];
}
vector <int> ans;
for (int half = 1; half < MAXN; half++) {
if (used[half])
ans.push_back(half);
}
cout << ans.size() << '\n';
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << ' ';
cout << '\n';
}
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... |