| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1235756 | dssfsuper2 | Detecting Molecules (IOI16_molecules) | C++20 | 44 ms | 7608 KiB | 
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> mapping;
vector<int> reversem;
vector<int> find_subset(int l, int u, vector<int> w) {
    vector<pair<int, int>> things;
    mapping.resize(w.size());
    for(int i = 0;i<w.size();i++){
        things.push_back({w[i], i});
    }
    sort(things.begin(), things.end());
    for(int i = 0;i<w.size();i++){
        reversem.push_back(things[i].second);
        mapping[things[i].second]=i;
    }
    sort(w.begin(), w.end());
    vector<int> prs, prss;
    int a = 0;
    for(int i = 0;i<w.size();i++){
        a+=w[i];
        prs.push_back(a);
    }
    a=0;
    for(int i = w.size()-1;i>=0;i--){
        a+=w[i];
        prss.push_back(a);
    }
    int res = -1;
    for(int i = 0;i<w.size();i++){
        if(prs[i]<=u && prss[i]>=l)res=i+1;
    }
    if(res==-1)return {};
    if (prs[res-1]>=l && prs[res-1]<=u){
        vector<int> ans;
        for(int i = 0;i<res;i++){
            ans.push_back(reversem[i]);
        }
        return ans;
    }
    if (prss[res-1]>=l && prss[res-1]<=u){
        vector<int> ans;
        for(int i = w.size()-1;i>=w.size()-res;i--){
            ans.push_back(reversem[i]);
        }
        return ans;
    }
    deque<int> ans;
    int tot=0;
    for(int i = 0;i<res;i++){
        ans.push_back(reversem[i]);
        tot+=w[i];
    }
    int end = w.size()-1;
    while(tot<l ){
        tot-=w[mapping[ans.front()]];
        tot+=w[end];
        ans.pop_front();
        ans.push_back(reversem[end]);
        end--;
    }
    vector<int> ansv;
    for(auto thing:ans)ansv.push_back(thing);
    return ansv;
}
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... | ||||
