This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
//#define LOCAL
#ifndef LOCAL
#include "molecules.h"
#endif // LOCAL
struct T {
int a, b;
T(int aa, int bb) : a(aa), b(bb) {}
};
const int N = 1e4 + 2;
int f[N];
bool dd[N];
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
memset(f, -1, sizeof f);
f[0] = 0;
for (int i = 1; i <= u; ++i) {
int &ret = f[i];
for (int j = n; j >= 1; --j) {
if (i - w[j - 1] < 0) continue;
if (f[i - w[j - 1]] > - 1 && f[i - w[j - 1]] < j) f[i] = j;
}
}
int j = 0;
for (int i = 1; i <= u; ++i) if (f[i] > -1) j = i;
vector<int> answer;
while (j > 0) {
cerr << j << '\n';
answer.push_back(f[j] - 1);
j = j - w[f[j] - 1];
}
return answer;
}
#ifdef LOCAL
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
int l, u; cin >> l >> u;
int x;
vector<int> input;
while (cin >> x) input.push_back(x);
for (auto i : find_subset(l, u, input))
cout << i << ' ';
}
#endif // LOCAL
Compilation message (stderr)
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:26:10: warning: unused variable 'ret' [-Wunused-variable]
26 | int &ret = f[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... |