Submission #169967

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

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

using namespace std;

int* find_subset(int l, int u, vector<int> w){
    ll sum = 0;
    vector<ll> returnThis;
    sort(w.begin(), w.end());
    for(ll i = 0;i < w.size();i++){
        sum += w[i];
        if(sum <= u && sum >= l){
            for(ll j = 0;j <= i;j++){
                returnThis.push_back(w[i]);
            }
            return &returnThis[0];
        } else if(sum > l){
            sum -= w[i];
            for(ll j = i;j < w.size();j++){
                sum += w[j]-w[j-i];
                if(sum <= u && sum >= l){
                    for(ll j = 0;j <= i;j++){
                        returnThis.push_back(w[i]);
                    }
                    return &returnThis[0];
                }
                if(j == w.size()-1){
                    return {};
                }
            }
        }
    }
    return {};
}

Compilation message

molecules.cpp: In function 'int* find_subset(int, int, std::vector<int>)':
molecules.cpp:14:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(ll i = 0;i < w.size();i++){
                  ~~^~~~~~~~~~
molecules.cpp:20:33: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type* {aka long long int*}' to 'int*' in return
             return &returnThis[0];
                                 ^
molecules.cpp:23:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(ll j = i;j < w.size();j++){
                          ~~^~~~~~~~~~
molecules.cpp:29:41: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type* {aka long long int*}' to 'int*' in return
                     return &returnThis[0];
                                         ^
molecules.cpp:31:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(j == w.size()-1){
                    ~~^~~~~~~~~~~~~