Submission #900092

#TimeUsernameProblemLanguageResultExecution timeMemory
900092mannshah1211Detecting Molecules (IOI16_molecules)C++14
0 / 100
1 ms684 KiB
#include "molecules.h" #include <bits/stdc++.h> std::vector<int> find_subset(int l, int u, std::vector<int> w) { int sum = 0; for (int i = 0; i < w.size(); i++) { sum += w[i]; } if (sum < l) { return {}; } std::vector<std::pair<int, int>> indices; for (int i = 0; i < w.size(); i++) { indices.push_back(std::make_pair(w[i], i)); } if (indices[0].first > u) { return {}; } std::sort(indices.begin(), indices.end()); int cursum = 0, longest = 0; for (int i = 0; i < indices.size(); i++) { cursum += indices[i].first; if (cursum >= l) { cursum -= indices[i].first, longest = i; break; } } for (int i = longest; i < indices.size(); i++) { cursum += indices[i].first; cursum -= indices[i - longest].first; if (cursum >= l && cursum <= u) { std::vector<int> answer; for (int j = i; j >= i - longest + 1; j--) { answer.push_back(indices[j].second); } return answer; } } return {}; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:6:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |    for (int i = 0; i < w.size(); i++) {
      |                    ~~^~~~~~~~~~
molecules.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < w.size(); i++) {
      |                     ~~^~~~~~~~~~
molecules.cpp:21: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]
   21 |     for (int i = 0; i < indices.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
molecules.cpp:28:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = longest; i < indices.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...