# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36063 | UncleGrandpa925 | Bootfall (IZhO17_bootfall) | C++14 | 6 ms | 4128 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;
void add(int x) {
for (int i = sum; i >= 0; i--) {
f[i + x] += f[i];
if (f[i + x] >= mod) f[i + x] -= mod;
}
sum += x;
}
void sub(int x) {
for (int i = 0; i <= sum; i++) {
f[i + x] += (mod - f[i]);
if (f[i + x] >= mod) f[i + x] -= mod;
}
sum -= x;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
f[0] = 1;
for (int i = 1; i <= n; i++) cin >> a[i], add(a[i]);
if (sum % 2 || f[sum / 2] == 0) {
cout << 0 << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
sub(a[i]);
int sta = 1; if (sum % 2 == 0) sta++;
for (int j = sta; j <= sum; j += 2) {
if (f[(sum + j) / 2 - j])
mark[j]++;
}
add(a[i]);
}
for (int i = 1; i <= sum; i++) if (mark[i] == n) order.push_back(i);
cout << order.size() << endl;
cout << order << endl;
}
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... |