Submission #526311

#TimeUsernameProblemLanguageResultExecution timeMemory
526311BelguteiDetecting Molecules (IOI16_molecules)C++17
19 / 100
1 ms332 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++){
        if(tot+w[i].ff<=u){
            v.pb(w[i].ss);
            tot+=w[i].ff;
        }
        else{
            pos=i;
            break;
        }
    }
    if(tot>=l) return v;
    if(pos==-1){
        v.clear();
        return v;
    }
    int ehlel=0;
    for(int i=pos; i<w.size(); i++){
        tot+=w[i].ff;
        v.pb(w[i].ss);
        tot-=w[v[ehlel]].ff;
        ehlel++;
        if(tot>=l) break;
    }
    vector<int> ans;
    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:22: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]
   22 |     for(int i=0; i<w.size(); i++){
      |                  ~^~~~~~~~~
molecules.cpp:38: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]
   38 |     for(int i=pos; i<w.size(); i++){
      |                    ~^~~~~~~~~
molecules.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         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...