# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
574061 | Elias | 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>
#ifndef _DEBUG
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include "molecules.h"
#endif
using namespace std;
#define int int64_t
vector<int> find_subset(int l, int u, vector<int> w)
{
vector<int> a;
for (int x : w)
{
if (x > u)
continue;
if (x >= l)
return {x};
a.push_back(x);
}
int n = a.size();
vector<vector<bool>> dp(n + 1, vector<bool>(u + 1));
for (int i = 0; i <= n; i++)
dp[i][0] = 1;
int i, j;
for (i = 1; i <= n; i++)
for (j = 1; j <= u; j++)
{
dp[i][j] = dp[i - 1][j];
if (a[i - 1] <= j)
dp[i][j] = dp[i][j] | dp[i - 1][j - a[i - 1]];
if (j >= l && dp[i][j])
goto out;
}
return {};
out:
vector<int> o;
while (i)
{
if (!dp[i - 1][j])
{
o.push_back(a[i - 1]);
j -= a[i - 1];
}
i--;
}
return o;
}
#ifdef _DEBUG
signed main()
{
int n, l, u;
cin >> n >> l >> u;
vector<int> a(n);
for (int &x : a)
cin >> x;
for (int x : find_subset(l, u, a))
cout << x << " ";
}
#endif