Submission #289418

#TimeUsernameProblemLanguageResultExecution timeMemory
289418BasilhijazDetecting Molecules (IOI16_molecules)C++17
46 / 100
3 ms768 KiB
#include "molecules.h" #include<bits/stdc++.h> using namespace std; std::vector<int> find_subset(int l, int u, std::vector<int> w) { vector<pair<int, int> > vec; vector<int> ans; int aa = 0; for(int i = 0; i < w.size(); i++){ vec.push_back({w[i], i}); aa += w[i]; if(w[i] >= l && w[i] <= u){ ans.push_back(i); return ans; } } sort(vec.begin(), vec.end()); int sum = vec[0].first; int p1 = 0, p2 = 0; if(vec[0].first > u || aa < l)return ans; while(p1 <= p2){ if(sum >= l && sum <= u)break; if(sum > u){ sum -= vec[p1].first; p1++; } else{ p2++; if(p2 == vec.size())break; sum += vec[p2].first; } } if(sum < l || sum > u)return ans; for(int i = p1; i <= p2; i++){ ans.push_back(vec[i].second); } return ans; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:10:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i = 0; i < w.size(); i++){
      |                    ~~^~~~~~~~~~
molecules.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             if(p2 == vec.size())break;
      |                ~~~^~~~~~~~~~~~~
#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...