Submission #491950

#TimeUsernameProblemLanguageResultExecution timeMemory
491950MassimilianoFDetecting Molecules (IOI16_molecules)C++14
0 / 100
0 ms204 KiB
#include "molecules.h" #include <vector> #include <algorithm> using namespace std; struct molecola { int pos; int weight; }; bool operator<(const molecola & lhs, const molecola & rhs) { return lhs.weight>rhs.weight; } std::vector<int> find_subset(int l, int u, std::vector<int> w) { int i, j, k, n, S=0; vector<int> t; n=w.size(); vector<molecola> V; for (i=0; i<n; i++) { V.push_back({i, w[i]}); S+=w[i]; } if (S<l) return t; sort(V.begin(), V.end()); i=0; S=0; while (S<l) { S+=V[i].weight; i++; } if (S<=u) { for (j=0; j<i; j++) { t.push_back(V[i].pos); return t; } } j=0; i--; S-=V[i].weight; while (j+i<=n && S<l) { S-=V[j].weight; S+=V[j+i].weight; j++; } if (j+i>n) return t; for (k=j; k<j+i; k++) { t.push_back(V[k].pos); } return t; }
#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...