Submission #44839

#TimeUsernameProblemLanguageResultExecution timeMemory
44839RayaBurong25_1Detecting Molecules (IOI16_molecules)C++17
100 / 100
86 ms25872 KiB
#include "molecules.h" #include <stdio.h> #include <algorithm> int compare(std::pair<long long, int> a, std::pair<long long, int> b) { return (a.first < b.first || (a.first == b.first && a.second < b.second)); } std::vector<int> find_subset(int l, int u, std::vector<int> w) { std::vector<std::pair<long long, int> > W; std::vector<int> V; int n = w.size(), i, j; long long mn = 0, mx = 0; for (i = 0; i < n; i++) W.push_back({w[i], i}); std::sort(W.begin(), W.end(), compare); for (i = 0; i < n; i++) { mn += W[i].first; mx += W[n - 1 - i].first; // printf("mn %d mx %d\n", mn, mx); if ((l <= mx && mx <= u) || (l <= mn && mn <= u) || (mn <= l && u <= mx)) break; } if (i == n) return V; for (j = 0; j <= i; j++) V.push_back(j); while (mn < l) { if (V[i] == n - (j - i)) i--; mn -= W[V[i]].first; V[i] = n - (j - i); mn += W[V[i]].first; } for (i = 0; i < V.size(); i++) V[i] = W[V[i]].second; return V; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:36:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < V.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...