Submission #1011991

#TimeUsernameProblemLanguageResultExecution timeMemory
1011991hotboy2703Detecting Molecules (IOI16_molecules)C++17
100 / 100
44 ms4952 KiB
#include "molecules.h"

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    int n = sz(w);
    vector <int> order(n);
    iota(order.begin(),order.end(),0);
    sort(order.begin(),order.end(),[&](ll x,ll y){return w[x] < w[y];});
    ll sum_L,sum_R;
    sum_L=sum_R=0;
    for (ll i = 0;i < n;i ++){
        sum_L += w[order[i]];
        sum_R += w[order[n-1-i]];
//        cout<<sum_L<<' '<<sum_R<<endl;
        if (sum_L > u || sum_R < l)continue;
        vector <int> res;
        if (l <= sum_L && sum_L <= u){
            for (ll j = 0;j <= i;j ++)res.push_back(order[j]);
        }
        else if (l <= sum_R && sum_R <= u){
            for (ll j = n - i - 1;j < n;j ++)res.push_back(order[j]);
        }
        else{
            for (ll j = 0;j <= i;j ++)res.push_back(order[j]);
            ll sum = sum_L;
            for (ll j = i;j >= 0;j --){
                sum += w[order[n-1-i+j]] - w[res[j]];
                res[j] = order[n-1-i+j];
                if (sum >= l){
                    break;
                }
            }
        }
        return res;
    }
    return std::vector<int>(0);
}
#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...