Submission #959419

#TimeUsernameProblemLanguageResultExecution timeMemory
959419Mystic03Detecting Molecules (IOI16_molecules)C++17
69 / 100
36 ms5584 KiB
#include "molecules.h" #include <algorithm> using namespace std; std::vector<int> find_subset(int l, int u, std::vector<int> w) { int p1 = 0; int r = 0; int n = w.size(); std::vector<pair<int, int>> ele; for (int i = 0; i < n; i++) { ele.push_back({ w[i], i }); } sort(ele.begin(), ele.end()); int currSum = 0; while (currSum < l) { if (r == ele.size()) return std::vector<int>(0); currSum += ele[r].first; r++; } vector<int> res; if (currSum <= u) { for (int i = 0; i < r; i++) { res.push_back(ele[i].second); } return res; } r--; currSum -= ele[r].first; for (int i = r; i < ele.size(); i++) { currSum += ele[i].first; currSum -= ele[p1++].first; if (currSum >= l && currSum <= u) { for (int j = p1; j <= i; j++) { res.push_back(ele[j].second); } return res; } } return std::vector<int>(0); }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:19: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]
   19 |         if (r == ele.size())    return std::vector<int>(0);
      |             ~~^~~~~~~~~~~~~
molecules.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i = r; i < ele.size(); 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...