Submission #299135

#TimeUsernameProblemLanguageResultExecution timeMemory
299135azategaDetecting Molecules (IOI16_molecules)C++11
9 / 100
1 ms256 KiB
#include "molecules.h" #include <vector> #include <algorithm> using namespace std; #define ll long long vector<int> find_subset(int l, int u, vector<int> w) { vector<pair<ll, int>> new_w; vector<int> bl; ll tot_sum = 0; for(int i = 0; i < w.size(); i++){ tot_sum += w[i]; new_w.push_back({w[i], i}); } sort(new_w.begin(), new_w.end()); if(tot_sum < l || new_w[0].first > u) return bl; ll currsum = 0; int tot_sum_idx = 0; for(int i = 0; i < new_w.size(); i++){ currsum += new_w[i].first; while(tot_sum_idx <= i || (tot_sum_idx < new_w.size() && tot_sum+currsum > u)){ tot_sum -= new_w[tot_sum_idx].first; tot_sum_idx++; } if(tot_sum + currsum >= l && tot_sum + currsum <= u){ vector<int> res; for(int x = 0; x <= i; x++) res.push_back(new_w[x].second); for(int x = tot_sum_idx; x < new_w.size(); x++) res.push_back(new_w[x].second); return res; } } return bl; } /*int main(){ int n, l, u; vector<int> niz; cin >> n >> l >> u; niz.resize(n); for(int i = 0; i < n; i++) cin >> niz[i]; vector<int> rs = find_subset(l, u, niz); for(int i = 0; i < rs.size(); i++) cout << rs[i] << endl; }*/

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:14:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i = 0; i < w.size(); i++){
      |                 ~~^~~~~~~~~~
molecules.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < new_w.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
molecules.cpp:29:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |      while(tot_sum_idx <= i || (tot_sum_idx < new_w.size() && tot_sum+currsum > u)){
      |                                 ~~~~~~~~~~~~^~~~~~~~~~~~~~
molecules.cpp:38:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    for(int x = tot_sum_idx; x < new_w.size(); x++)
      |                             ~~^~~~~~~~~~~~~~
#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...