Submission #997095

#TimeUsernameProblemLanguageResultExecution timeMemory
997095codefoxDetecting 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; for (int i = 0; i < sizeof(w); i++) nums.push_back({w[i], i}); 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:10:29: warning: 'sizeof' on array function parameter 'w' will return size of 'int*' [-Wsizeof-array-argument]
   10 |  for (int i = 0; i < sizeof(w); i++) nums.push_back({w[i], i});
      |                            ~^~
molecules.cpp:7:37: note: declared here
    7 | int * find_subset(int l, int u, int w[])
      |                                 ~~~~^~~
molecules.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
   10 |  for (int i = 0; i < sizeof(w); i++) nums.push_back({w[i], i});
      |                  ~~^~~~~~~~~~~
molecules.cpp:40:10: warning: address of local variable 'ans' returned [-Wreturn-local-addr]
   40 |   return ans;
      |          ^~~
molecules.cpp:35:7: note: declared here
   35 |   int ans[right-left];
      |       ^~~
molecules.cpp:45:10: warning: address of local variable 'ans' returned [-Wreturn-local-addr]
   45 |   return ans;
      |          ^~~
molecules.cpp:44:7: note: declared here
   44 |   int ans[0];
      |       ^~~
/usr/bin/ld: /tmp/ccr70ih2.o: in function `main':
grader.cpp:(.text.startup+0x18d): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status