Submission #1192297

#TimeUsernameProblemLanguageResultExecution timeMemory
1192297Mousa_AboubakerDetecting Molecules (IOI16_molecules)C++20
100 / 100
33 ms4796 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; vector<int> find_subset(int l, int u, vector<int> w) { priority_queue<pair<int, int>> pq; long long curr = 0; int n = w.size(); vector<int> ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int l, int r) { return w[l] < w[r]; }); for(int j = n - 1; j >= 0; j--) { int i = ord[j]; while(not pq.empty() and curr + w[i] > u) { auto [u, k] = pq.top(); curr -= u; pq.pop(); } if(curr + w[i] > u) continue; pq.push({w[i], i}); curr += w[i]; if(curr >= l and curr <= u) break; } if(curr < l) { return {}; } vector<int> res; while(not pq.empty()) { auto [u, j] = pq.top(); res.push_back(j); pq.pop(); } sort(res.begin(), res.end()); return res; }

Compilation message (stderr)

molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...