Submission #164694

# Submission time Handle Problem Language Result Execution time Memory
164694 2019-11-22T16:18:49 Z DS007 Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second

vector<int> find_subset(int l, int u, vector<int> w) {
    vector<pair<int, int>> v;
    for (int i = 0; i < w.size(); i++)
        v.emplace_back(w[i], i);
    sort(v.begin(), v.end());

    vector<int> ans;
    int low = 1, high = w.size(), mid;
    while (low <= high) {
        mid = (low + high) / 2;
        int sum = 0, p1 = 0, p2 = mid;
        for (int i = 0; i < mid; i++)
            sum += v[i].x;

        bool check = sum < l;
        for (int i = mid; i < w.size() && check; i++) {
            p1++, p2++;
            sum += v[i].x - v[i - mid].x;
            check = sum < l;
        }

        if (!check && sum <= u) {
            for (int i = p1; i < p2; i++)
                ans.push_back(v[i].y);
            return ans;
        }

        if (check)
            low = mid + 1;
        else
            high = mid - 1;
    }

    return ans;
}

/*signed main() {
    int n, l, u;
    assert(3 == scanf("%d %d %d", &n, &l, &u));
    std::vector<int> w(n);
    for (int i = 0; i < n; i++)
        assert(1 == scanf("%d", &w[i]));
    std::vector<int> result = find_subset(l, u, w);


    printf("%d\n", (int)result.size());
    for (int i = 0; i < (int)result.size(); i++)
        printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}*/

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:9:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < w.size(); i++)
                     ~~^~~~~~~~~~
molecules.cpp:22:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = mid; i < w.size() && check; i++) {
                           ~~^~~~~~~~~~
/tmp/ccHCQkfK.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