Submission #170053

# Submission time Handle Problem Language Result Execution time Memory
170053 2019-12-23T19:57:44 Z whttt Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB

#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long

//#include "molecules.h"

using namespace std;

vector<int> find_subset(int l, int u, vector<int> w){
    ll sum = 0;
    vector<int> returnThis;
    vector<pair<int, int>> sol;
    for(ll i = 0;i < w.size();i++){
        sol.push_back({w[i],i});
    }
    sort(sol.begin(), sol.end());
    for(ll i = 0;i < sol.size();i++){
        sum += sol[i].first;
        //cout << sum << endl;
        if(sum <= u && sum >= l){
            for(ll j = 0;j <= i;j++){
                returnThis.push_back(sol[j].second);
            }
            return returnThis;
        } else if(sum > u){
            sum -= sol[i].first;
            //cout << "prvych " << i << " nestaci" << endl;
            for(ll j = i;j < sol.size();j++){
                sum += sol[j].first-sol[j-i].first;
                //cout << sol[j].first << " priratane a " << sol[j-i].first << " odratane" << endl;
                if(sum <= u && sum >= l){
                    for(ll k = j-i+1;k <= j;k++){
                        returnThis.push_back(sol[k].second);
                    }
                    return returnThis;
                }
                if(j == sol.size()-1){
                    return {};
                }
            }
        }
    }
    return {};
}

int main(int argc, const char * argv[]) {
    int n,l,u;
    cin >> n >> l >> u;
    vector<int> input;
    int temp;
    for(ll i = 0;i < n;i++){
        cin >> temp;
        input.push_back(temp);
    }
    vector<int> sol = find_subset(l, u, input);
    cout << sol.size() << endl;
    for(ll i = 0;i < sol.size();i++){
        if(i != 0){
            cout << " ";
        }
        cout << sol[i];
    }
    return 0;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(ll i = 0;i < w.size();i++){
                  ~~^~~~~~~~~~
molecules.cpp:20:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(ll i = 0;i < sol.size();i++){
                  ~~^~~~~~~~~~~~
molecules.cpp:31:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(ll j = i;j < sol.size();j++){
                          ~~^~~~~~~~~~~~
molecules.cpp:40:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(j == sol.size()-1){
                    ~~^~~~~~~~~~~~~~~
molecules.cpp: In function 'int main(int, const char**)':
molecules.cpp:60:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(ll i = 0;i < sol.size();i++){
                  ~~^~~~~~~~~~~~
/tmp/ccFDYGgK.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccwERNBQ.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status