# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
410955 | Marceantasy | Detecting Molecules (IOI16_molecules) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
#define ll long long
const int mxN = 2e5;
map<pair<ll, int>, bool> mp;
vector<int> solve(ll pts, int pos, bitset<200000>& bs, int l, int u, vector<int> w){
vector<int> ans;
if(pos == n){
if(pts >= l && pts <= u){
for(int i = 0; i<bs.size(); ++i){
if(bs[i]){
ans.push_back(i);
}
}
}
return ans;
}
if(pts > u || mp[{pts, pos}] || pos > n){
return ans;
}
mp[{pts, pos}] == 1;
if(pts >= l && pts <= u){
vector<int> ans;
for(int i = 0; i<bs.size(); ++i){
if(bs[i]){
ans.push_back(i);
}
}
return ans;
}
bs[pos] = 1;
vector<int> intento1 = solve(pts+w[pos], pos+1, bs, l, u, w);
if(intento1.size()){
return intento1;
}else{
bs[pos] = 0;
vector<int> intento2 = solve(pts, pos+1, bs, l, u, w);
if(intento2.size()){
return intento2;
}else{
return ans;
}
}
return ans;
}
vector<int> find_subset(int l, int u, vector<int> w){
bitset<200000> bt;
vector<int> ans = solve(0, 0, bt, l, u, w);
return ans;
}