이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |