Submission #1360071

#TimeUsernameProblemLanguageResultExecution timeMemory
1360071skuruDetecting Molecules (IOI16_molecules)C++20
31 / 100
1095 ms2736 KiB
#include "molecules.h"
#include <bitset>
using namespace std;

constexpr int MAX_U = 500001;

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

    bitset<MAX_U> dp;
    vector<int> from(MAX_U, -1);
    dp[0] = dp[w[0]] = true;
    from[w[0]] = 0;

    for (int i = 1; i < n; i++) {
        bitset<MAX_U> added = (dp << w[i]) & ~dp;
        
        bitset<MAX_U> temp = added;
        while (temp.any()) {
            int j = temp._Find_first();
            from[j] = i;
            temp[j] = false;
        }
        
        dp |= added;
    }

    int j = l;
    for (; j <= u; j++) {
        if (from[j] != -1)
            break;
    }
    if (j > u)
        return {};

    vector<int> ret = {};
    for (int i = from[j]; i >= 0; i = from[j]) {
        j -= w[i];
        ret.push_back(i);
    }

    return ret;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...