Submission #879324

#TimeUsernameProblemLanguageResultExecution timeMemory
879324dilshod9890Bootfall (IZhO17_bootfall)C++17
6 / 100
1061 ms66380 KiB
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #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; }

Compilation message (stderr)

bootfall.cpp: In function 'void rec(std::vector<int>, int, std::vector<int>&)':
bootfall.cpp:13:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     if (i == a.size()) {
      |         ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...