CSES - Aalto Competitive Programming 2024 - wk1 - Wed - Results
Submission details
Task:LumberUolevi
Sender:aalto2024a_012
Submission time:2024-09-04 17:13:11 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void combinations(int, int)':
input/code.cpp:8:10: error: 'vector' is not a member of 'std'
    8 |     std::vector<bool> v(n);
      |          ^~~~~~
input/code.cpp:4:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | 
input/code.cpp:8:17: error: expected primary-expression before 'bool'
    8 |     std::vector<bool> v(n);
      |                 ^~~~
input/code.cpp:9:15: error: 'v' was not declared in this scope
    9 |     std::fill(v.begin(), v.begin() + r, true);
      |               ^
input/code.cpp:13:14: error: 'vector' is not a member of 'std'
   13 |         std::vector<int> trees(r);
      |              ^~~~~~
input/code.cpp:13:14: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
input/code.cpp:13:21: error: expected primary-expression before 'int'
   13 |         std::vector<int> trees(r);...

Code

#include <iostream>
#include <string>
#include <algorithm>


void combinations(int n, int r) {

    std::vector<bool> v(n);
    std::fill(v.begin(), v.begin() + r, true);

    do {
        int weight_sum = 0;
        std::vector<int> trees(r);

        for (int i = 0; i < n; ++i) {
            if (v[i]) {
                // std::cout << (i + 1) << " ";
                weight_sum += (i + 1);
                trees.push_back(i + 1);
            }
        }
        // std::cout << " Sum: " << weight_sum << "\n";

        // check if weight fits in trucks with minimal left over space
        if (weight_sum % 10 == 0) {

            for (int tree : trees) {
               std::cout << tree << " ";
            }

            break;
        }

        trees.clear();

    } while (std::prev_permutation(v.begin(), v.end()));
}

int main() {
    
    int forest_size, number_of_trees;
    std::cin >> forest_size >> number_of_trees;

    int truck_capacity = forest_size;
    
    combinations(forest_size, number_of_trees);


    return 0;
}