Submission #959418

#TimeUsernameProblemLanguageResultExecution timeMemory
959418Mystic03Detecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms856 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 == w.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 < w.size(); i++) { currSum += ele[i].first; currSum -= ele[p1++].first; if (currSum >= l && currSum <= u) { for (int i = p1; i <= i; i++) { res.push_back(ele[i].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<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         if (r == w.size())    return std::vector<int>(0);
      |             ~~^~~~~~~~~~~
molecules.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int i = r; i < w.size(); i++) {
      |                     ~~^~~~~~~~~~
molecules.cpp:39:32: warning: self-comparison always evaluates to true [-Wtautological-compare]
   39 |             for (int i = p1; i <= i; 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...