Submission #770651

#TimeUsernameProblemLanguageResultExecution timeMemory
770651BenmathDetecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
//#include<bits/stdc++.h> #include "molecules.h" using namespace std; std::vector<int> find_subset(int l, int u, std::vector<int> w) { long long int sum=0; vector<int>ans; vector<pair<long long int,int> >arr; int n=w.size(); for(int i=0;i<w.size();i++){ arr.push_back({w[i],i}); } sort(arr.begin(),arr.end()); if(arr[0].first>u){ return ans; }else if(arr[0].first>=l and arr[0].first<=u){ ans.push_back(arr[0].second); return ans; }else{ if(arr[n-1].first>=l and arr[n-1].first<=u){ ans.push_back(arr[n-1].second); return ans; }else{ int ti1=0; int ti2=-1; long long int sum=0; for(int i=0;i<n;i++){ sum=sum+arr[i].first; if(sum<l){ ti1=i; }else if(sum>=l and sum<=u){ for(int j=0;j<=i;j++){ ans.push_back(arr[j].second); } return ans; }else{ ti2=i; break; } } if(ti2==-1){ return ans; }else{ long long int sum1=0; for(int i=n-1;i>=(n-ti1-1);i--){ sum1=sum1+arr[i].first; } if(sum1<l){ return ans; } int j=n-1; sum=sum-arr[ti2].first; for(int i=ti1;i>=0;i--){ sum=sum+arr[j].first-arr[i].first; if(sum>=l and sum<=u){ for(int k=0;k<i;k++){ ans.push_back(arr[k].second); } for(int k=j;k<=(n-1);k++){ ans.push_back(arr[k].second); } return ans; } j--; } } } } for(int i=0;i<w.size();i++){ if(w[i]<=u){ sum=sum+w[i]; ans.push_back(i); } if(sum>=l and sum<=u){ break; } } if(sum>=l and sum<=u){ return ans; }else{ ans.clear(); return ans;} } /* int main() { int n, l, u; assert(3 == scanf("%d %d %d", &n, &l, &u)); std::vector<int> w(n); for (int i = 0; i < n; i++) assert(1 == scanf("%d", &w[i])); std::vector<int> result = find_subset(l, u, w); printf("%d\n", (int)result.size()); for (int i = 0; i < (int)result.size(); i++) printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]); } */

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:11:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |    for(int i=0;i<w.size();i++){
      |                ~^~~~~~~~~
molecules.cpp:14:4: error: 'sort' was not declared in this scope; did you mean 'short'?
   14 |    sort(arr.begin(),arr.end());
      |    ^~~~
      |    short
molecules.cpp:70:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |    for(int i=0;i<w.size();i++){
      |                ~^~~~~~~~~