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;
vector<int> find_subset(int l, int u, vector<int> w)
{
vector<int> a;
for (int i = 0; i < w.size(); i++)
{
if (w[i] > u)
continue;
if (w[i] >= l)
return {i};
a.push_back(w[i]);
}
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 && j <= u && dp[i][j])
goto out;
}
return {};
out:
vector<int> o;
while (i)
{
if (!dp[i - 1][j])
{
o.push_back(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
Compilation message (stderr)
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < w.size(); i++)
| ~~^~~~~~~~~~
# | 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... |