Submission #431067

#TimeUsernameProblemLanguageResultExecution timeMemory
431067davi_bartDetecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms256 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> w) {
    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(i);
        tot+=w[i];
        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-=w[ans[pos]];
        ans[pos]=i;
        tot+=w[ans[pos]];
        pos++;
        if(pos>=ans.size())break;
        if(tot<=u)break;
    }
    
    if(tot>=l && tot<=u)return ans;
    ans.clear();

    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:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
molecules.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=w.size()-1;i>=ans.size();i++){
      |                          ~^~~~~~~~~~~~
molecules.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         if(pos>=ans.size())break;
      |            ~~~^~~~~~~~~~~~
molecules.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
molecules.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i=w.size()-1;i>=ans.size();i++){
      |                          ~^~~~~~~~~~~~
molecules.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         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...