Submission #330223

#TimeUsernameProblemLanguageResultExecution timeMemory
330223saarthakDetecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms364 KiB
#include <bits/stdc++.h> #include "molecules.h" struct weights { int wt; int idx; }; bool cmp(weights a, weights b) { return (a.wt < b.wt); } std::vector<int> find_subset(int l, int u, std::vector<int> w) { int n = w.size(); if(l == u) { if(l%w[0] == 0 && l/w[0] <= n) { //all weights equal std::vector<int> ans(l/w[0]); for(int i = 0; i < ans.size(); i++) ans[i] = i; return ans; } else return std::vector<int>(); //no subarray found } int total_weight = 0, i = 0; std::queue<int> indices; std::vector<struct weights> wts(n); for(int i = 0; i < n; i++) wts[i] = {w[i], i}; std::sort(wts.begin(), wts.end(), cmp); while(total_weight < l) { total_weight += wts[i].wt; indices.push(wts[i++].idx); } i = 0; while(total_weight > u) { total_weight -= wts[i++].wt; indices.pop(); } if(total_weight < l || total_weight > u) return std::vector<int>(); //no subarray found std::vector<int> ans(indices.size()); i = 0; while(!indices.empty()) { ans[i++] = indices.front(); indices.pop(); } return ans; }

Compilation message (stderr)

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