Submission #997093

#TimeUsernameProblemLanguageResultExecution timeMemory
997093codefoxDetecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int, int> int * find_subset(int l, int u, int w[]) { vector<pii> nums; int c = 1; for (int ele:w) nums.push_back({ele, c++}); sort(nums.begin(), nums.end()); int left=0, right=0; long long sum = 0; while (sum <= l) { sum += nums[right].first; right++; } right--; sum -= nums[right].first; while (sum <= u) { sum += nums[right].first; right++; sum -= nums[left].first; left++; } right--; sum -= nums[right].first; left--; sum -= nums[left].first; if (sum >= l) { int ans[right-left]; for (int i = left; i < right; i++) { ans[i-left] = nums[i].second; } return ans; } else { int ans[0]; return ans; } }

Compilation message (stderr)

molecules.cpp: In function 'int* find_subset(int, int, int*)':
molecules.cpp:11:15: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   11 |  for (int ele:w) nums.push_back({ele, c++});
      |               ^
      |               std::begin
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from molecules.cpp:1:
/usr/include/c++/10/valarray:1224:5: note: 'std::begin' declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
molecules.cpp:11:15: error: 'end' was not declared in this scope; did you mean 'std::end'?
   11 |  for (int ele:w) nums.push_back({ele, c++});
      |               ^
      |               std::end
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from molecules.cpp:1:
/usr/include/c++/10/valarray:1244:5: note: 'std::end' declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
molecules.cpp:41:10: warning: address of local variable 'ans' returned [-Wreturn-local-addr]
   41 |   return ans;
      |          ^~~
molecules.cpp:36:7: note: declared here
   36 |   int ans[right-left];
      |       ^~~
molecules.cpp:46:10: warning: address of local variable 'ans' returned [-Wreturn-local-addr]
   46 |   return ans;
      |          ^~~
molecules.cpp:45:7: note: declared here
   45 |   int ans[0];
      |       ^~~