답안 #877310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877310 2023-11-23T06:14:22 Z AI_2512 Bootfall (IZhO17_bootfall) C++
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <numeric>
 
bool splitArrayHelper(const std::vector<int>& nums, std::vector<int>::size_type index index, int sum1, int sum2, std::vector<int>& arr1, std::vector<int>& arr2) {
    if (index == nums.size()) {
        return sum1 == sum2;
    }
 
    arr1.push_back(nums[index]);
    if (splitArrayHelper(nums, index + 1, sum1 + nums[index], sum2, arr1, arr2)) {
        return true;
    }
    arr1.pop_back();
 
    arr2.push_back(nums[index]);
    if (splitArrayHelper(nums, index + 1, sum1, sum2 + nums[index], arr1, arr2)) {
        return true;
    }
    arr2.pop_back();
 
    return false;
}
 
bool splitArray(const std::vector<int>& nums, std::vector<int>& arr1, std::vector<int>& arr2) {
    int sum1 = 0, sum2 = 0;
    return splitArrayHelper(nums, 0, sum1, sum2, arr1, arr2);
}
 
int main() {
    int n;
    std::cin >> n;
 
    std::vector<int> arr, arr2, arr3, res;
 
    // Input array
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        arr.push_back(a);
    }
 
    int sum = std::accumulate(arr.begin(), arr.end(), 0);
    bool ruined = false;
 
    for (int i = 1; i <= sum; i++) {
        ruined = false;
        int size = arr.size();
 
        if (size > 0) {
            arr.erase(arr.end() - 1);
        }
 
        arr.push_back(i);
 
        for (int k = 0; k < n; k++) {
            std::vector<int> tempArr = arr;
            tempArr.erase(tempArr.begin() + k);
 
            if (!splitArray(tempArr, arr2, arr3)) {
                ruined = true;
                break;
            }
 
            arr2.clear();
            arr3.clear();
        }
 
        if (!ruined) {
            res.push_back(i);
        }
    }
 
    std::cout << res.size() << std::endl;
 
    if (res.size() > 0) {
        for (const auto& element : res) {
            std::cout << element << " ";
        }
    }
 
    return 0;
}

Compilation message

bootfall.cpp:5:87: error: expected ',' or '...' before 'index'
    5 | bool splitArrayHelper(const std::vector<int>& nums, std::vector<int>::size_type index index, int sum1, int sum2, std::vector<int>& arr1, std::vector<int>& arr2) {
      |                                                                                       ^~~~~
bootfall.cpp: In function 'bool splitArrayHelper(const std::vector<int>&, std::vector<int>::size_type)':
bootfall.cpp:7:16: error: 'sum1' was not declared in this scope
    7 |         return sum1 == sum2;
      |                ^~~~
bootfall.cpp:7:24: error: 'sum2' was not declared in this scope
    7 |         return sum1 == sum2;
      |                        ^~~~
bootfall.cpp:10:5: error: 'arr1' was not declared in this scope
   10 |     arr1.push_back(nums[index]);
      |     ^~~~
bootfall.cpp:11:43: error: 'sum1' was not declared in this scope
   11 |     if (splitArrayHelper(nums, index + 1, sum1 + nums[index], sum2, arr1, arr2)) {
      |                                           ^~~~
bootfall.cpp:11:63: error: 'sum2' was not declared in this scope
   11 |     if (splitArrayHelper(nums, index + 1, sum1 + nums[index], sum2, arr1, arr2)) {
      |                                                               ^~~~
bootfall.cpp:11:75: error: 'arr2' was not declared in this scope
   11 |     if (splitArrayHelper(nums, index + 1, sum1 + nums[index], sum2, arr1, arr2)) {
      |                                                                           ^~~~
bootfall.cpp:16:5: error: 'arr2' was not declared in this scope
   16 |     arr2.push_back(nums[index]);
      |     ^~~~
bootfall.cpp:17:43: error: 'sum1' was not declared in this scope
   17 |     if (splitArrayHelper(nums, index + 1, sum1, sum2 + nums[index], arr1, arr2)) {
      |                                           ^~~~
bootfall.cpp:17:49: error: 'sum2' was not declared in this scope
   17 |     if (splitArrayHelper(nums, index + 1, sum1, sum2 + nums[index], arr1, arr2)) {
      |                                                 ^~~~
bootfall.cpp: In function 'bool splitArray(const std::vector<int>&, std::vector<int>&, std::vector<int>&)':
bootfall.cpp:27:60: error: too many arguments to function 'bool splitArrayHelper(const std::vector<int>&, std::vector<int>::size_type)'
   27 |     return splitArrayHelper(nums, 0, sum1, sum2, arr1, arr2);
      |                                                            ^
bootfall.cpp:5:6: note: declared here
    5 | bool splitArrayHelper(const std::vector<int>& nums, std::vector<int>::size_type index index, int sum1, int sum2, std::vector<int>& arr1, std::vector<int>& arr2) {
      |      ^~~~~~~~~~~~~~~~