Submission #281894

#TimeUsernameProblemLanguageResultExecution timeMemory
281894A02Detecting Molecules (IOI16_molecules)C++14
100 / 100
146 ms13672 KiB
#include "molecules.h" #include <vector> #include <iostream> #include <set> #include <algorithm> #include <utility> using namespace std; std::vector<int> find_subset(int l, int u, std::vector<int> w) { vector<pair<int, int> > w2; for (int i = 0; i < w.size(); i++){ w2.push_back(make_pair(w[i], i)); } sort(w2.begin(), w2.end()); long long total = 0; set<int> result; int i = 0; for (; (i < w2.size()) && (total + w2[i].first <= u); i++){ total += w2[i].first; result.insert(w2[i].second); } int result_size = i; long long max_total = 0; for (int j = w2.size() - 1; j >= (int) w2.size() - result_size; j--){ max_total += w2[j].first; } if (max_total < l){ return vector<int> (); } int current_lower_max = i - 1; while (total < l){ result.erase(w2[current_lower_max].second); result.insert(w2[w2.size() - 1 - (i - 1 - current_lower_max)].second); total += w2[w.size() - 1 - (i - 1 - current_lower_max)].first; total -= w2[current_lower_max].first; current_lower_max--; } vector<int> r; for (set<int>::iterator it = result.begin(); it != result.end(); it++){ r.push_back(*(it)); } return r; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:14:23: 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:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (; (i < w2.size()) && (total + w2[i].first <= u); 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...