#include <bits/stdc++.h>
using namespace std;
using ii = pair<int,int>;
using ll = long long;
constexpr int MAXN = 5+1e4;
constexpr ll INF = 1LL<<50;
ll memo[MAXN][MAXN];
ll dp(int i, int s, const vector<int>& w) {
const int n = (int)w.size();
if (s <= 0) return 0;
if (i == n) return INF;
ll& ans = memo[i][s];
if (ans != -1) return ans;
return ans = min(dp(1+i,s,w), w[i]+dp(1+i, s-w[i], w));
}
void go(int i, int s, const vector<int>& w, vector<int>& res) {
const int n = (int)w.size();
if (i == n || s <= 0) return;
const ll d = dp(i,s,w);
if (dp(1+i,s,w) == d) {
go(1+i, s, w, res);
return;
}
assert(d == w[i]+dp(1+i, s-w[i], w));
res.push_back(i);
go(1+i, s-w[i], w, res);
}
vector<int> find_subset(int l, int u, vector<int> w) {
memset(memo, -1, sizeof memo);
ll s = dp(0, l, w);
if (s >= l && s <= u) {
vector<int> idx;
go(0, l, w, idx);
return idx;
}
return {};
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
50 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
48 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
50 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
50 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
50 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
50 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |