Submission #784971

#TimeUsernameProblemLanguageResultExecution timeMemory
784971BoasDetecting Molecules (IOI16_molecules)C++17
9 / 100
1083 ms2772 KiB
#include "molecules.h"

using namespace std;
#include <bits/stdc++.h>


#define MAX_N 200001

typedef vector<int> vi;

int L{};
int U{};

int n{};

vi mols;

vi addMolecule(const int &w, const bitset<MAX_N> &used)
{
    for (int i = 0; i < n; i++)
    {
        int nw = w + mols[i];
        if (nw > U)
            continue;
        if (used[i])
            continue;
        if (nw >= L)
        {
            vi solution = {i};
            for (int i = 0; i < mols.size(); i++)
            {
                if (used[i])
                    solution.push_back(i);
            }
            return solution;
        }
        bitset<MAX_N> newUsed(used);
        newUsed[i] = true;
        auto ret = addMolecule(nw, newUsed);
        if (ret.size() > 0)
            return ret;
    }
    return {};
}

vi find_subset(int l, int u, vi w)
{
    n = w.size();
    bool allSame = true;
    for (int i = 1; i < n; i++)
    {
        if (w[i] != w[i - 1])
        {
            allSame = false;
            break;
        }
    }
    if (allSame)
    {
        int s = 0;
        int i = 0;
        vi res;
        for (int i = 0; i < n; i++)
        {
            s += w[0];
            res.push_back(i);
            if (s > u)
                break;
            if (s >= l)
                return res;
        }
        return {};
    }
    L = l;
    U = u;
    mols = w;
    return addMolecule(0, {});
}

Compilation message (stderr)

molecules.cpp: In function 'vi addMolecule(const int&, const std::bitset<200001>&)':
molecules.cpp:30:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             for (int i = 0; i < mols.size(); i++)
      |                             ~~^~~~~~~~~~~~~
molecules.cpp: In function 'vi find_subset(int, int, vi)':
molecules.cpp:61:13: warning: unused variable 'i' [-Wunused-variable]
   61 |         int i = 0;
      |             ^
#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...