Submission #526315

#TimeUsernameProblemLanguageResultExecution timeMemory
526315BelguteiDetecting Molecules (IOI16_molecules)C++17
100 / 100
53 ms7068 KiB
#include "molecules.h"
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair

vector<int> v;
vector<pair<int,int> > w;

std::vector<int> find_subset(int l, int u, std::vector<int> W) {
    ll tot=0;
    ll pos=-1;
    for(int i=0; i<W.size(); i++){
        w.pb(mk(W[i],i));
    }
    sort(w.begin(),w.end());
    /*
    for(int i=0; i<w.size(); i++){
        cout<<w[i].ff<<" "<<w[i].ss<<'\n';
    }
    cout<<"\n";
    */
    for(int i=0; i<w.size(); i++){
        if(tot+w[i].ff<=u){
            v.pb(w[i].ss);
            tot+=w[i].ff;
        }
        else{
            pos=i;
            break;
        }
    }
    if(l<=tot && tot<=u) return v;
    if(pos==-1){
        v.clear();
        return v;
    }
    //cout<<pos<<"\n";
    int ehlel=0;
    for(int i=pos; i<w.size(); i++){
        //cout<<w[i].ff<<" "<<w[ehlel].ff<<"\n";
        //cout<<i<<" "<<w[ehlel].ss<<"\n\n";
        tot+=w[i].ff;
        v.pb(w[i].ss);
        tot-=w[ehlel].ff;
        ehlel++;
        if(tot>=l) break;
    }
    vector<int> ans;
    ans.clear();
    if(l<=tot && tot<=u){
        for(int i=ehlel; i<v.size(); i++){
            ans.pb(v[i]);
        }
    }
    return ans;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0; i<W.size(); i++){
      |                  ~^~~~~~~~~
molecules.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=0; i<w.size(); i++){
      |                  ~^~~~~~~~~
molecules.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=pos; i<w.size(); i++){
      |                    ~^~~~~~~~~
molecules.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for(int i=ehlel; i<v.size(); i++){
      |                          ~^~~~~~~~~
#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...