Submission #321796

# Submission time Handle Problem Language Result Execution time Memory
321796 2020-11-13T11:46:54 Z nikatamliani Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
vector<int> find_subset(int l, int u, vector<int>w, int n) {
    vector<int> indices(n);
    for(int i = 0; i < n; ++i) {
        indices[i] = i; 
    }
    sort(indices.begin(), indices.end(), [&](int x, int y) {
        return w[x] > w[y];
    });
    #define ll long long
    vector<int> result;
    ll sum = 0, cnt = 0, save = 0;
    for(int i = 0; i < n; ++i) {
        int index = indices[i]; 
        sum += w[index];
        result.push_back(index);
        ++cnt;
        if(sum >= l) {
            save = i + 1;
            break;
        }
    }
    int ptr = 0; 
    while(save < n && sum > u) {
        assert(ptr < result.size());
        sum -= result[ptr];
        result[ptr] = indices[save++];
        sum += result[ptr++];
    }
    if(sum <= u) {
        assert(sum >= l);
        return result;
    }
    return vector<int>{};
}

Compilation message

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from molecules.cpp:1:
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>, int)':
molecules.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         assert(ptr < result.size());
      |                ~~~~^~~~~~~~~~~~~~~
/tmp/ccoKOgIq.o: In function `main':
grader.cpp:(.text.startup+0x139): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status