Submission #877296

#TimeUsernameProblemLanguageResultExecution timeMemory
877296AI_2512Bootfall (IZhO17_bootfall)C++14
0 / 100
0 ms344 KiB
#include <iostream> #include <vector> #include <numeric> using namespace std; bool splitArrayHelper(const vector<int>& nums, auto index, int sum1, int sum2, vector<int>& arr1, vector<int>& arr2) { auto i = index; if (i == 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 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; auto z = 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; if (arr.size() > z){ arr.erase(arr.end()); } 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; }

Compilation message (stderr)

bootfall.cpp:6:48: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
    6 | bool splitArrayHelper(const vector<int>& nums, auto index, int sum1, int sum2, vector<int>& arr1, vector<int>& arr2) {
      |                                                ^~~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:49:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |         if (arr.size() > z){
      |             ~~~~~~~~~~~^~~
bootfall.cpp: In instantiation of 'bool splitArrayHelper(const std::vector<int>&, auto:1, int, int, std::vector<int>&, std::vector<int>&) [with auto:1 = int]':
bootfall.cpp:29:60:   required from here
bootfall.cpp:8:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     if (i == nums.size()) {
      |         ~~^~~~~~~~~~~~~~
bootfall.cpp:35:10: warning: 'n' is used uninitialized in this function [-Wuninitialized]
   35 |     auto z = n;
      |          ^
#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...