| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1223385 | 12baater | Detecting Molecules (IOI16_molecules) | C++20 | 2 ms | 584 KiB | 
#include "molecules.h"
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int U, L, N;
int 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;
    int testTot = 0;
    for(int i = 0; i < n; i++) {
        testTot += w[i];
    }
    if (testTot < l) {
        return vector<int>(0);
    }
    int i = n;
    while (total <= u) {
        i--;
        ans.push(numbers[i].index);
        total += numbers[i].n;
        if (check()) {
            return q_to_v(ans);
        }
    }
    int lower = 0;
    while(lower < i) {
        total -= w[ans.front()];
        ans.pop();
        total += numbers[lower].n;
        ans.push(numbers[lower].index);
        lower++;
        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... | ||||
