Submission #877307

#TimeUsernameProblemLanguageResultExecution timeMemory
877307AI_2512Bootfall (IZhO17_bootfall)C++98
0 / 100
0 ms344 KiB
#include <iostream> #include <vector> #include <numeric> bool splitArrayHelper(const std::vector<int>& nums, int 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 (stderr)

bootfall.cpp: In function 'bool splitArrayHelper(const std::vector<int>&, int, int, int, std::vector<int>&, std::vector<int>&)':
bootfall.cpp:6:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     if (index == nums.size()) {
      |         ~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...