Submission #651355

#TimeUsernameProblemLanguageResultExecution timeMemory
651355pauloamedDetecting Molecules (IOI16_molecules)C++17
0 / 100
0 ms212 KiB
#include<bits/stdc++.h> #include "molecules.h" using namespace std; vector<int> find_subset(int l, int u, vector<int> w){ int n = w.size(); vector<pair<int,int>> W; for(int i = 0; i < n; ++i){ W.push_back({w[i], i}); } sort(W.begin(), W.end()); vector<int> ans; for(int i = 0; i < W.size(); ++i){ int mini = W[i].first; int id_mini = W[i].second; int maxi = W.back().first; int id_maxi = W.back().second; if(mini > u) return {}; else if(mini >= l){ ans.push_back(id_mini); return ans; }else{ // mini ta a esquerda // maxi ta dentro ou a esquerda if(maxi > u) return {}; ans.push_back(id_maxi); if(maxi >= l){ // maxi ta dentro return ans; }else{ // maxi ta a esquerda l -= maxi; u -= maxi; } W.pop_back(); } } if(0 >= l && 0 <= u) return ans; else return {}; } // int32_t main(){ // auto ret = find_subset(15, 17, {6,8,8,7}); // for(auto x : ret) cout << x << " "; // cout << "\n"; // ret = find_subset(14, 15, {5, 5, 6, 6}); // for(auto x : ret) cout << x << " "; // cout << "\n"; // ret = find_subset(10, 20, {15, 17, 16, 18}); // for(auto x : ret) cout << x << " "; // cout << "\n"; // }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:15:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |   for(int i = 0; i < W.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...