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 <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define PF push_front
#define PB push_back
#define MP make_pair
#define max(a, b) ((a > b)? a : b)
#define min(a, b) ((a < b)? a : b)
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
const int N = 2e5 + 5;
const int M = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll int INF = 1e18;
vector<int> find_subset(int l, int u, vector<int> w){
// DP may pass O(NU)
const int MAXN = 1e4 + 5;
vector<int> dp(MAXN, false), parent(MAXN, -1);
dp[0] = true;
int ans = -1;
for(int i = 0; i < (int)w.size() && ans == -1; i++){
for(int j = u; j >= w[i] && ans == -1; j--){
if(dp[j]) continue;
dp[j] |= dp[j - w[i]];
if(dp[j]) parent[j] = i;
if(dp[j] && j >= l) ans = j;
}
}
vector<int> v;
if(ans < l || ans > u) return v;
for(int cur = ans; cur > 0; cur -= w[parent[cur]]){
v.PB(parent[cur] + 1);
}
return v;
}
// int main(){
// ios::sync_with_stdio(false);
// cin.tie(NULL);
// // ifstream cin();
// // ofstream cout();
// vector<int> temp;
// // temp = find_subset(15, 17, {6, 8, 8, 7});
// // temp = find_subset(14, 15, {5, 5, 6, 6});
// // temp = find_subset(10, 20, {15, 17, 16, 18});
// for(int i : temp){
// cout << 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... |