Submission #612026

#TimeUsernameProblemLanguageResultExecution timeMemory
612026boris_mihovDetecting Molecules (IOI16_molecules)C++14
69 / 100
17 ms4280 KiB
#include "molecules.h"
#include <algorithm>
#include <numeric>

typedef long long llong;
const int MAXN = 100000 + 10;

int perm[MAXN], n;
std::vector <int> find_subset(int l, int u, std::vector <int> w) 
{
    n = w.size();
    std::iota(perm+1, perm+1+n, 0);
    std::sort(perm+1, perm+1+n, [&](int x, int y)
    {
        return w[x] < w[y];
    });

    std::sort(w.begin(), w.end());

    int lp = 1, sum = 0;
    for (int rp = 1 ; rp <= w.size() ; ++rp)
    {
        sum += w[rp - 1];
        while (sum > u) sum -= w[lp++ - 1];
        if (l <= sum && sum <= u)
        {
            std::vector <int> ans;
            for (int j = lp ; j <= rp ; ++j)
            {
                ans.push_back(perm[j]);
            }

            return ans;
        }
    }

    return {};
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:21:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int rp = 1 ; rp <= w.size() ; ++rp)
      |                       ~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...