Submission #1211220

#TimeUsernameProblemLanguageResultExecution timeMemory
1211220madamadam3Detecting Molecules (IOI16_molecules)C++20
46 / 100
8 ms328 KiB
#include "molecules.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX_SUM = 10'000;
using bset = bitset<MAX_SUM+1>;

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

    vector<int> par(MAX_SUM + 1, -1);
    bset possible;
    possible.set(0);

    for (int i = 0; i < n; i++) {
        bset nw = (possible | (possible << w[i])) ^ possible;
        possible |= (possible << w[i]);

        size_t pos = nw._Find_first();
        while (pos != nw.size()) {
            par[pos] = i;
            pos = nw._Find_next(pos);
        }
    }

    // for (int i = 0; i <= u; i++) {
    //     cout << i << "\t";
    // }
    // cout << "\n";
    // for (int i = 0; i <= u; i++) {
    //     cout << par[i] << "\t";
    // }
    // cout << "\n";
    
    vector<int> ans;
    int first_valid = 0;
    for (int i = l; i <= u; i++) {
        if (par[i] != -1) {
            first_valid = i;
            break;
        }
    }
    
    while (first_valid != 0) {
        ans.push_back(par[first_valid]);
        first_valid = first_valid - w[par[first_valid]];
    }

    // for (auto &el : ans) {
    //     cout << el << " ";
    // }
    // cout << "\n";

    return ans;
}

Compilation message (stderr)

molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...