# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1102162 | akzytr | 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 "molecules.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
vector<int> result;
int n = w.size();
bool dp[u + 1];
bool dp2[u + 1];
int back[u + 1];
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= u; j++) {
dp[i][j] = 0;
back[j] = -1;
}
}
dp[0] = 1;
back[0] = 0;
for(int i = 1; i <= n; i++) {
for(int s = 0; s <= u; s++) {
if(s < w[i - 1]) {
dp2[s] = dp[s];
}
else if(dp[s - w[i - 1]]) {
dp2[s] = 1;
if(back[s] == -1) {
back[s] = i;
}
} else {
dp2[s] = dp[s];
}
}
for(int s = 0; s <= u; s++) {
dp[s] |= dp2[s];
}
}
for(int i = l; i <= u; i++) {
if(back[i] != -1) {
int idx = back[i];
int s = i;
while(idx != 0) {
result.push_back(idx - 1);
s -= w[idx - 1];
idx = back[s];
}
break;
}
}
return result;
}