# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36067 | UncleGrandpa925 | Bootfall (IZhO17_bootfall) | C++14 | 1000 ms | 4824 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.
/*input
4
1 3 1 5
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define N 505
#define bit(x,y) ((x>>y)&1LL)
#define na(x) (#x) << ":" << x
ostream& operator << (ostream &os, vector<int>&x) {
for (int i = 0; i < x.size(); i++) os << x[i] << sp;
return os;
}
ostream& operator << (ostream &os, pair<int, int> x) {
cout << x.fi << sp << x.se << sp;
return os;
}
ostream& operator << (ostream &os, vector<pair<int, int> >&x) {
for (int i = 0; i < x.size(); i++) os << x[i] << endl;
return os;
}
const int mod = 1e9 + 7;
int n;
int a[N];
int f[250005];
int sum = 0;
int mark[250005];
vector<int> order;
bool used[N];
signed main() {
scanf("%d", &n);
f[0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
int x = a[i];
for (int i = sum; i >= 0; i--) {
f[i + x] += f[i];
if (f[i + x] >= mod) f[i + x] -= mod;
}
sum += x;
}
if (sum % 2 || f[sum / 2] == 0) {
printf("0\n");
return 0;
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (used[a[i]]) continue;
used[a[i]] = true; cnt++;
int x = a[i];
for (int i = 0; i <= sum; i++) {
f[i + x] += (mod - f[i]);
if (f[i + x] >= mod) f[i + x] -= mod;
}
sum -= x;
int sta = 1; if (sum % 2 == 0) sta++;
for (int j = sta; j <= sum; j += 2) {
if (f[((sum + j) >> 1) - j])
mark[j]++;
}
for (int i = sum; i >= 0; i--) {
f[i + x] += f[i];
if (f[i + x] >= mod) f[i + x] -= mod;
}
sum += x;
}
for (int i = 1; i <= sum; i++) if (mark[i] == cnt) order.push_back(i);
printf("%d\n", order.size());
for (int i = 0; i < order.size(); i++) {
printf("%d ", order[i]);
}
}
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... |