# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1223441 | 12baater | Detecting Molecules (IOI16_molecules) | C++20 | 39 ms | 4132 KiB |
#include "molecules.h"
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
int U, L, N;
ll total = 0;
struct number {
int n;
int index;
bool operator<(const number& other) const {
return n < other.n;
}
};
bool check() {
return (total >= L && total <= U);
}
vector<int> q_to_v(queue<int>& q) {
vector<int> retVec;
for (;!q.empty();q.pop()) {
retVec.push_back(q.front());
}
return retVec;
}
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
N = n; U = u; L = l;
vector<number> numbers;
for (int i = 0; i < w.size(); i++) {
number num;
num.n = w[i];
num.index = i;
numbers.push_back(num);
}
sort(numbers.begin(),numbers.end());
queue<int> ans;
ll testTot = 0;
for(int i = 0; i < n; i++) {
testTot += w[i];
}
if (testTot < l) { return vector<int>(0); }
int i = 0;
while (total <= u) {
ans.push(numbers[i].index);
total += numbers[i].n;
if (check()) {
return q_to_v(ans);
}
i++;
}
vector<int> returnVector;
int lower = 0;
while (!check()) {
if (total > u) {
if (lower == n) break;
total -= numbers[lower].n;
lower++;
ans.pop();
}
if (total < l) {
if (i == n) break;
total += numbers[i].n;
ans.push(numbers[i].index);
i++;
}
if (check()) {
return q_to_v(ans);
}
}
return vector<int>(0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |