이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize ("Ofast")
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define mp make_pair
#define pb push_back
map<pair<int, int>, int> dp;
vi sb;
int findSubset(int x, int r, vi &w) {
if (r == 0) return 0;
if (x == 0) {
if (w[x] <= r) {
return w[x];
}
return 0;
}
auto it = dp.find(mp(x, r));
if (it != dp.end()) return it->second;
return dp[mp(x, r)] = max(
findSubset(x-1, r, w),
(w[x] <= r ? findSubset(x-1, r-w[x], w)+w[x] : 0)
);
}
void constructAns(int x, int r, vi &w) {
if (r == 0) return;
if (x == 0) {
if (w[x] <= r) {
sb.pb(x);
}
return;
}
if (w[x] > r) {
constructAns(x-1, r, w);
return;
}
int c1 = dp[mp(x-1, r)];
int c2 = dp[mp(x-1, r-w[x])]+w[x];
if (c1 > c2) {
constructAns(x-1, r, w);
}
else {
sb.pb(x);
constructAns(x-1, r-w[x], w);
}
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int n = w.size();
findSubset(n-1, u, w);
if (dp[mp(n-1, u)] >= l) {
constructAns(n-1, u, w);
return sb;
}
return vector<int>(0);
}
# | 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... |