Submission #335121

#TimeUsernameProblemLanguageResultExecution timeMemory
335121blueDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include "molecules.h"
#include <vector>
#include <algorithm>
using namespace std;

vector<int> W;
int n;

vector<int> find_subset(int l, int u, vector<int> w)
{
    W = w;
    n = w.size();

    int i, x;

    vector<int> I(n);
    for(i = 0; i < n; i++) I[i] = i;

    sort(I.begin(), I.end(), [] (int x, int y)
    {
        return W[x] < W[y];
    });

    int sum = 0;
    vector<int> empty_res;
    vector<int> res;

    if(w[I[0]] > u) return empty_res;

    for(x = 0; x < n && sum < l; x++)
    {
        i = I[x];
        sum += w[i];
        res.push_back(i);
    }
    if(sum < l) return empty_res;
    x--;
    sum -= x[I[x]];
    res.pop_back();

    res.push_back(I[n-1]);
    return res;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:38:18: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   38 |     sum -= x[I[x]];
      |                  ^