Submission #877678

# Submission time Handle Problem Language Result Execution time Memory
877678 2023-11-23T12:33:37 Z AI_2512 Bootfall (IZhO17_bootfall) C++
6 / 100
1000 ms 348 KB
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

bool splitArrayHelper(const vector<int>& nums,int index, int sum1, int sum2, vector<int>& arr1, vector<int>& arr2) {
    int size = nums.size();
    if (index == 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 vector<int>& nums, vector<int>& arr1, vector<int>& arr2) {
    int sum1 = 0, sum2 = 0;
    return splitArrayHelper(nums, 0, sum1, sum2, arr1, arr2);
}

int main() 
{
    int n;
    cin >> n;
    vector<int> arr;
    vector<int> arr2,arr3;
    vector<int> res;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        arr.push_back(a);
    }
    int sum = accumulate(arr.begin(), arr.end(), 0);
    bool ruined = false;
    for (int i = 1; i<=sum; i++){
        ruined = false;
        int size = arr.size();
        if (size > n){
            arr.erase(arr.begin()+ ((int) arr.size()-1));
            }
        arr.push_back(i);
            for (int k = 0; k<=n; k++){
                vector<int> darr = arr;
                darr.erase(darr.begin()+k);
                if (splitArray(darr, arr2, arr3) == false){
                    ruined = true;
                    break;
                }
                arr2.clear();
                arr3.clear();
        }
        if (ruined == false){
            res.push_back(i);
        }
    }
    
    cout << res.size()<<endl;
    if (res.size()>0){
        for (const auto& element : res){
            cout << element << " ";
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 36 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 54 ms 348 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 36 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 54 ms 348 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Execution timed out 1089 ms 348 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 36 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 54 ms 348 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Execution timed out 1089 ms 348 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 36 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 54 ms 348 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Execution timed out 1089 ms 348 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 36 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 54 ms 348 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Execution timed out 1089 ms 348 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 36 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 54 ms 348 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Execution timed out 1089 ms 348 KB Time limit exceeded
11 Halted 0 ms 0 KB -