Submission #431079

#TimeUsernameProblemLanguageResultExecution timeMemory
431079davi_bartDetecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms204 KiB
#include "molecules.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ld long double
#define pb push_back
std::vector<int> find_subset(int l, int u, std::vector<int> p) {
    vector<pair<int,int> > w;
    for(int i=0;i<p.size();i++)w.pb({p[i],i});
    vector<int> ans;
    int tot=0;
    sort(w.begin(),w.end());
    reverse(w.begin(),w.end());
    for(int i=0;i<w.size();i++){
        ans.pb(w[i].se);
        tot+=w[i].fi;
        if(tot>=l)break;
    }

    if(tot>=l && tot<=u)return ans;
    int pos=0;
    for(int i=w.size()-1;i>=ans.size();i++){
        tot-=p[ans[pos]];
        ans[pos]=w[i].se;
        tot+=p[ans[pos]];
        pos++;
        if(pos>=ans.size())break;
        if(tot<=u)break;
    }
    
    if(tot>=l && tot<=u)return ans;
    ans.clear();
    return ans;
    /*tot=0;
    sort(w.begin(),w.end());
    for(int i=0;i<w.size();i++){
        ans.pb(i);
        tot+=w[i];
        if(tot>=l)break;
    }

    if(tot>=l && tot<=u)return ans;
    tot-=w[ans.back()];
    ans.pop_back();

    pos=0;
    for(int i=w.size()-1;i>=ans.size();i++){
        tot-=w[ans[pos]];
        ans[pos]=i;
        tot+=w[ans[pos]];
        pos++;
        if(pos>=ans.size())break;
        if(tot>=l && tot<=u)break;
    }
    if(tot>=l && tot<=u)return ans;
    ans.clear();
    return ans;*/
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0;i<p.size();i++)w.pb({p[i],i});
      |                 ~^~~~~~~~~
molecules.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
molecules.cpp:25:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=w.size()-1;i>=ans.size();i++){
      |                          ~^~~~~~~~~~~~
molecules.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         if(pos>=ans.size())break;
      |            ~~~^~~~~~~~~~~~
#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...