Submission #196924

# Submission time Handle Problem Language Result Execution time Memory
196924 2020-01-17T18:05:56 Z Swan Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "molecules.h"
#define stop system("pause")
#define stop2 char o; cin >> o
#define INP freopen("cowrect.in","r",stdin)
#define OUTP freopen ("cowrect.out","w",stdout)
#define int long long
using namespace std;



vector<int> find_subset(int l, int u, vector<int> w) {
    vector<pair<int,int> > start;
    for(int i(0); i < w.size();i++){
        start.push_back({w[i],i});
    }
    sort(start.begin(),start.end());
    sort(w.begin(),w.end());
    if(w[0] > u)return {};
    int res = 0;
    for(int i(0); i < w.size();i++){
        res+=w[i];
    }
    if(res < l)return {};
    if(res>=l && res<=u){
        return w;
    }
    res = 0;
    set<pair<int,int> > s;
    int cnt = 0;
    int pnt = 0;
    for(int i(0); i < w.size();i++){
        if(res + w[i] > u)break;
        res+=w[i];
        cnt++;
        s.insert({w[i],i});
        pnt++;
    }
    //cout << res << ' ' << cnt << endl;
    vector<int> v;
    while(cnt){
        int now = s.begin()->first;
        res-=now;
        res+=w[pnt];
        s.erase(s.begin());
        s.insert({w[pnt],pnt});
        pnt++;
        cnt--;
        //cout << res << ' ' << l << ' ' << u << endl;
        if(pnt == w.size())break;
        if(res>=l && res <=u){
            int pnt = 0;
            for(auto& a: s)v.push_back(start[a.second].second);
            break;
        }
    }
    //cout << res << endl;
    return v;
}

/*
main(){
    ios_base::sync_with_stdio(0);
    int l,u,n; cin >> l >> u >> n;
    vector<int> v;
    for(int i(0); i < n;i++){
        int x; cin >> x;
        v.push_back(x);
    }
    vector<int> ans = find_subset(l,u,v);
    for(int i(0); i < ans.size();i++)cout << ans[i] << ' ';
    return 0;
}*/

/*
15 17 4
6 8 8 7
14 15 4
5 5 6 6
10 20 4
15 17 16 18

*/

Compilation message

molecules.cpp: In function 'std::vector<long long int> find_subset(long long int, long long int, std::vector<long long int>)':
molecules.cpp:14:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i(0); i < w.size();i++){
                   ~~^~~~~~~~~~
molecules.cpp:21:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i(0); i < w.size();i++){
                   ~~^~~~~~~~~~
molecules.cpp:32:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i(0); i < w.size();i++){
                   ~~^~~~~~~~~~
molecules.cpp:50:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(pnt == w.size())break;
            ~~~~^~~~~~~~~~~
molecules.cpp:52:17: warning: unused variable 'pnt' [-Wunused-variable]
             int pnt = 0;
                 ^~~
/tmp/cc4FJ5e1.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