# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
571052 | web | Detecting Molecules (IOI16_molecules) | C++17 | 1 ms | 296 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 <iostream>
#include "molecules.h"
#include <algorithm>
using namespace std;
vector<vector<int>> dp;
void knapsack(vector<int>& weights, int u)
{
for(int i = 0; i<weights.size(); ++i)
{
for(int weight = 0; weight <= u; ++weight)
{
if(weight < weights[i])
{
dp[i+1][weight] = dp[i][weight];
}
else
{
if(dp[i][weight] >= dp[i][weight - weights[i]]+ weights[i])
{
dp[i+1][weight] = dp[i][weight];
}
else
{
dp[i+1][weight] = dp[i][weight-weights[i]] + weights[i];
}
}
}
}
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
dp = vector<vector<int>>(w.size()+1, vector<int>(u+1));
knapsack(w, u);
int resWeight = dp[w.size()][u];
if(resWeight < l)
return vector<int>(0);
vector<int> retVal;
for(int i = w.size(); i>=0 && resWeight > 0; --i)
{
if(resWeight == dp[i][u])
continue;
else
{
retVal.push_back(i+1);
resWeight-=w[i];
u -= w[i];
}
}
return retVal;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |