This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <numeric>
bool splitArrayHelper(const std::vector<int>& nums, std::vector<int>::size_type 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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |