# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879323 | dilshod9890 | Bootfall (IZhO17_bootfall) | C++17 | 0 ms | 0 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 <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int n;
vector<int> a;
void rec(vector<int>& b, int i, vector<int>& c) {
if (i == a.size()) {
c.push_back(abs(accumulate(a.begin(), a.end(), 0) - 2 * accumulate(b.begin(), b.end(), 0)));
return;
}
b.push_back(a[i]);
rec(b, i + 1, c);
b.pop_back();
rec(b, i + 1, c);
}
int main() {
cin >> n;
a.resize(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> c;
for (int i = 0; i < n; ++i) {
rec({}, 0, c);
}
if (*min_element(c.begin(), c.end()) != 0) {
cout << 0 << endl;
} else {
c.clear();
vector<set<int>> g;
for (int i = 0; i < n; ++i) {
int d = a[i];
a.erase(a.begin() + i);
rec({}, 0, c);
a.insert(a.begin() + i, d);
sort(c.begin(), c.end());
g.push_back(set<int>(c.begin(), c.end()));
c.clear();
}
set<int> c_set = g[0];
for (const auto& i : g) {
set<int> intersection_result;
set_intersection(c_set.begin(), c_set.end(), i.begin(), i.end(), inserter(intersection_result, intersection_result.begin()));
c_set = intersection_result;
}
vector<int> c_vector(c_set.begin(), c_set.end());
sort(c_vector.begin(), c_vector.end());
cout << c_vector.size() << endl;
for (int i : c_vector) {
cout << i << " ";
}
cout << endl;
}
return 0;
}