Submission #701097

#TimeUsernameProblemLanguageResultExecution timeMemory
701097mychecksedadDetecting Molecules (IOI16_molecules)C++17
19 / 100
1 ms340 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define all(x) x.begin(), x.end()

vector<int> find_subset(int l, int r, vector<int> w) {
    vector<pair<int, int>> a;
    for(int i = 0; i < w.size(); ++i) a.pb({w[i], i});
    sort(all(a));
    if(r < a[0].first){
        return vector<int>(0);
    }
    ll s = 0;
    for(int i = 0; i < a.size(); ++i){
        s += a[i].first;
    }
    if(s < l){
        return vector<int>(0);
    }
    set<int> ans;
    s = 0;

    for(int i = 0; i < a.size(); ++i){
        if(s + a[i].first > r){
            bool ok = 0;
            for(int j = a.size() - 1; j >= i; --j){
                ans.insert(a[j].second);
                ans.erase(a[a.size()-j-1].second);
                s += a[j].first - a[a.size() - j - 1].first;
                if(s >= l){
                    ok = 1;
                    break;
                }
            }
            if(!ok) return vector<int>(0);
            break;
        }
        ans.insert(a[i].second);
        s += a[i].first;
        if(s <= r && s >= l) break;
    }
    vector<int> A;
    for(int x: ans) A.pb(x);
    return A;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:10:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i = 0; i < w.size(); ++i) a.pb({w[i], i});
      |                    ~~^~~~~~~~~~
molecules.cpp:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 0; i < a.size(); ++i){
      |                    ~~^~~~~~~~~~
molecules.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i = 0; i < a.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...