# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1270147 | almaz | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 328 KiB |
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(), a.end()
// const int MOD = 1e9 + 7,INF = 1e18;
std::vector<int> find_subset(int l1, int u, std::vector<int> w) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n = w.size(), l = l1 , r = u;
if(l == 1 && r == 1){
while(true);
}
vector <int> a(n);
int sum = 0;
for(int i = 0;i < n;i++){
a[i] = w[i];
sum += a[i];
}
vector <int> dp(sum + 1);
dp[0] = 1;
for(int i = 0;i < n;i++){
for(int j = sum;j >= 0;j--){
if(j - a[i] >= 0){
if(dp[j - a[i]] == 1)
dp[j] = 1;
}
}
}
int ans = -1;
vector <int> b;
for(int i = l;i <= r;i++){
if(dp[i] == 1){
ans = i;
break;
}
}
if(ans == -1){
return b;
}
vector <int> use(n);
for(int i = 0;i < n;i++){
if(ans - a[i] >= 0 && dp[ans - a[i]] == 1 && use[i] == 0){
ans -= a[i];
b.pb(i + 1);
use[i] = 1;
}
}
return b;
}
Compilation message (stderr)
# | 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... |