Submission #707567

#TimeUsernameProblemLanguageResultExecution timeMemory
707567Error42Detecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms256 KiB
#include "molecules.h"

#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;

vector<int> find_subset(
    int const _l,
    int const _u,
    vector<int> _w
) {
    ll const l = _l;
    ll const u = _u;

    sort(_w.begin(), _w.end());
    
    vector<ll> const w(_w.begin(), _w.end());

    vector<ll> prefix(w.size() + 1);
    partial_sum(w.begin(), w.end(), prefix.begin() + 1);

    for (int mol_count = 1; mol_count <= w.size(); mol_count++) {
        int lo = 0;
        int hi = mol_count;

        while (lo <= hi) {
            int const mi = (lo + hi) / 2;
            int const top = mi;
            int const bottom = mol_count - mi; 

            ll val = prefix[bottom] + prefix[w.size()] - prefix[w.size() - top];

            if (l <= val && val <= u) {
                vector<int> solution;

                for (int i = 0; i < bottom; i++)
                    solution.push_back(i);

                for (int i = w.size() - top; i < w.size(); i++)
                    solution.push_back(i);

                return solution;
            }
            
            if (val < l)
                lo = mi + 1;
            else
                hi = mi - 1;
        }
    }

    return {};
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:25:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int mol_count = 1; mol_count <= w.size(); mol_count++) {
      |                             ~~~~~~~~~~^~~~~~~~~~~
molecules.cpp:42:48: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |                 for (int i = w.size() - top; i < w.size(); i++)
      |                                              ~~^~~~~~~~~~
#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...