이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "molecules.h"
#include <algorithm>
using namespace std;
#define pb push_back
vector<vector<vector<bool>>> knapsack(vector<int>& w, int sum, vector<vector<vector<bool>>>& dp){
int n = w.size();
if (w[0] <= sum) dp[1][0][w[0]] = true;
dp[0][0][0] = true;
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j <= sum; ++j) {
if (dp[0][i][j] || dp[1][i][j]){
dp[0][i+1][j] = true;
if (j + w[i+1] <= sum) dp[1][i+1][j + w[i+1]] = true;
}
}
}
return dp;
}
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
vector<vector<vector<bool>>> dp(2, vector<vector<bool>>(n, vector<bool>(u+1)));
knapsack(w, u, dp);
int res = -1;
for (int i = l; i <= u; ++i) {
if (dp[1][n-1][i] || dp[0][n-1][i]) {
res = i;
break;
}
i = u-1;
}
vector<int> ans;
if (res == -1) return ans;
for (int i = n-1; i >= 0; --i){
if (dp[1][i][res]){
ans.pb(i);
res -= w[i];
}
}
reverse(ans.begin(), ans.end());
return ans;
}
# | 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... |