Submission #289486

#TimeUsernameProblemLanguageResultExecution timeMemory
289486RuDi24Detecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms384 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 <int> ans; vector <pair<int,int> >wi(w.size()); for(int i = 0;i < w.size();i++){ wi[i].first = w[i]; wi[i].second = i; } ans.reserve(w.size()); sort(wi.begin(),wi.end()); long long sum = 0; int it; for(it = 0;it < w.size() && sum + w[it] <= u;it++){ sum += wi[it].first; ans.emplace_back(wi[it].second); } if(sum >= l && sum <= u) return ans; for(int i = 0;i < wi.size()-it;i++){ if(sum + (wi[it+i].first-wi[i].first) <= u){ sum+= wi[it+i].first-wi[i].first; ans[i] = wi[it+i].second; } if(sum >= l && sum <= u) return ans; } return vector <int> (0); } // int main(){ // auto a = find_subset(15, 17, {6, 8, 8, 7}); // for(int i = 0;i < a.size();i++){ // cout<<a[i]<<' '; // } // cout<<endl; // a = find_subset(14, 15, {5, 5, 6, 6}); // for(int i = 0;i < a.size();i++){ // cout<<a[i]<<' '; // } // cout<<endl; // a = find_subset(10, 20, {15, 17, 16, 18}); // for(int i = 0;i < a.size();i++){ // cout<<a[i]<<' '; // } // cout<<endl; // a = find_subset(22, 24, {12, 12, 12, 12}); // for(int i = 0;i < a.size();i++){ // cout<<a[i]<<' '; // } // cout<<endl; // }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for(int i = 0;i < w.size();i++){
      |                ~~^~~~~~~~~~
molecules.cpp:16:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for(it = 0;it < w.size() && sum + w[it] <= u;it++){
      |             ~~~^~~~~~~~~~
molecules.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(int i = 0;i < wi.size()-it;i++){
      |                ~~^~~~~~~~~~~~~~
#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...