Submission #139454

# Submission time Handle Problem Language Result Execution time Memory
139454 2019-07-31T18:28:16 Z medk Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include "molecules.h"
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define x first
#define y second

using namespace std;

vector<int> find_subset(int l, int u, vector<ll> w)
{
    vector<pair<ll,int>> pw;
    for(ll x:w) pw.pb({x,int(pw.size())});
    sort(pw.begin(),pw.end());
    ll sum=0;
    int ptr=0;
    vector<int> ans;
    bool flag=0;
    while(ptr<pw.size())
    {
        if(sum+pw[ptr].x<l) sum+=pw[ptr].x, flag=1;
        else if(sum+pw[ptr].x<=u)
        {
            ans.pb(pw[ptr].y);
            return ans;
        }
        else break;
        ans.pb(pw[ptr].y);
        ptr++;
    }
    if(!flag) return {};
    for(int i=0;i<ans.size() && pw.size()-1-i>=ans.size();i++)
    {
        sum+=pw[pw.size()-1-i].x-pw[i].x;
        ans[i]=pw[pw.size()-1-i].y;
        if(sum>=l) return ans;
    }
    return {};
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<long long int>)':
molecules.cpp:20:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(ptr<pw.size())
           ~~~^~~~~~~~~~
molecules.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ans.size() && pw.size()-1-i>=ans.size();i++)
                 ~^~~~~~~~~~~
/tmp/ccEX8n5Y.o: In function `main':
grader.cpp:(.text.startup+0x152): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status