Submission #879323

# Submission time Handle Problem Language Result Execution time Memory
879323 2023-11-27T06:51:50 Z dilshod9890 Bootfall (IZhO17_bootfall) C++17
Compilation error
0 ms 0 KB
#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;
}

Compilation message

bootfall.cpp: In function 'void rec(std::vector<int>&, int, std::vector<int>&)':
bootfall.cpp:12:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     if (i == a.size()) {
      |         ~~^~~~~~~~~~~
bootfall.cpp:13:25: error: 'accumulate' was not declared in this scope
   13 |         c.push_back(abs(accumulate(a.begin(), a.end(), 0) - 2 * accumulate(b.begin(), b.end(), 0)));
      |                         ^~~~~~~~~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:35:21: error: cannot bind non-const lvalue reference of type 'std::vector<int>&' to an rvalue of type 'std::vector<int>'
   35 |         rec({}, 0, c);
      |                     ^
In file included from /usr/include/c++/10/vector:67,
                 from bootfall.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:487:7: note:   after user-defined conversion: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = int; _Alloc = std::allocator<int>]'
  487 |       vector() = default;
      |       ^~~~~~
bootfall.cpp:11:23: note:   initializing argument 1 of 'void rec(std::vector<int>&, int, std::vector<int>&)'
   11 | void rec(vector<int>& b, int i, vector<int>& c) {
      |          ~~~~~~~~~~~~~^
bootfall.cpp:47:25: error: cannot bind non-const lvalue reference of type 'std::vector<int>&' to an rvalue of type 'std::vector<int>'
   47 |             rec({}, 0, c);
      |                         ^
In file included from /usr/include/c++/10/vector:67,
                 from bootfall.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:487:7: note:   after user-defined conversion: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = int; _Alloc = std::allocator<int>]'
  487 |       vector() = default;
      |       ^~~~~~
bootfall.cpp:11:23: note:   initializing argument 1 of 'void rec(std::vector<int>&, int, std::vector<int>&)'
   11 | void rec(vector<int>& b, int i, vector<int>& c) {
      |          ~~~~~~~~~~~~~^