Submission #988564

#TimeUsernameProblemLanguageResultExecution timeMemory
988564WaneDetecting Molecules (IOI16_molecules)C++14
0 / 100
1 ms504 KiB
#include <algorithm> #include <queue> #include <stack> #include <vector> #include "molecules.h" #define int long long #define pp std::pair<int, int> bool cmp1(pp a, pp b) { return a.first > b.first; } std::vector<signed> find_subset(signed l, signed u, std::vector<signed> w) { std::vector<pp> wp; for (int i = 0; i < w.size(); i++) wp.push_back({w[i], i}); // Notice that w_max - w_min is always smaller than u - l. sort(wp.begin(), wp.end(), cmp1); // We can just put ALL things down here first, and 'replace' them until it satisfies the condition; std::priority_queue<pp> q; std::priority_queue<pp> d; //cout << l << ' ' << u << '\n'; int man = 0; for (auto a : wp) { if (man > l) { //cout << a.first << " << D, "; d.push(a); // it means 'ready' queue continue; } //cout << a.first << " << Q, "; q.push(a); man += a.first; } //cout << "Man: " << man << '\n'; if (man < l) { return {}; // Impossible! } while (!d.empty() && man > u) { // Replace d's top and q's top, but there's no more usage for q's top so just fuck it off auto dt = d.top(); auto qt = q.top(); q.pop(); d.pop(); q.push(dt); man -= qt.first - dt.first; } if (man > u) { return {}; } std::vector<signed> ans; while (!q.empty()) { ans.push_back(q.top().second); //cout << q.top().second << ' '; q.pop(); } //cout << '\n'; return ans; } /* signed main() { int n, l, u; cin >> n >> l >> u; std::vector<int> w(n); for (int i = 0; i < n; i++) assert(1 == scanf("%d", &w[i])); //cout << l << ' ' << u << '\n'; std::vector<int> result = find_subset(l, u, w); printf("%d\n", (int)result.size()); for (int i = 0; i < (int)result.size(); i++) printf("%d ", result[i]); } */

Compilation message (stderr)

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