#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(), order_of_key()
typedef long long ll;
typedef long double dd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<dd, dd> pdd;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<dd> vdd;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vdd> vvdd;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
typedef vector<vpdd> vvpdd;
typedef vector<bool> vb;
const int inf = 1 << 30;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ffor(i, a, b) for(ll i = a; i < b; i++)
#define forin(x, a) for (auto &x: a)
#define all(x) x.begin(), x.end()
#ifdef TEST
#define dbg(x) cout << #x << ": " << x << '\n';
#define dbgc(x) cout << #x << ":"; forin(a, x) { cout << " " << a; } cout << endl;
#define tassert(x) assert(x);
#else
#define dbg(x)
#define dbgc(x)
#define tassert(x)
#endif
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
vpii nums;
ll tot = 0;
rep(i, w.size()) {
nums.emplace_back(w[i], i);
tot += w[i];
}
if (tot < l) {
return vii();
}
sort(nums.rbegin(), nums.rend());
map<int, int> reached;
reached[0] = -1;
for (auto &[num, i]: nums) {
for (auto it = reached.cbegin(); it != reached.cend();) {
if (it->second == i) {
it++;
continue;
}
if (it->first < l - tot) {
reached.erase(it++);
} else {
int k = it->first + num;
if (k > u || k < 0) {
break;
}
reached[num] = i;
it++;
}
}
if (reached.rbegin()->first >= l) {
break;
}
tot -= num;
}
vii res;
if (reached.rbegin()->first >= l) {
int curr = reached.rbegin()->first;
while (reached[curr] != -1) {
res.emplace_back(reached[curr]);
curr -= w[reached[curr]];
}
}
return res;
}
Compilation message
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:32:36: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | #define rep(i, n) for (ll i = 0; i < n; i++)
......
50 | rep(i, w.size()) {
| ~~~~~~~~~~~
molecules.cpp:50:3: note: in expansion of macro 'rep'
50 | rep(i, w.size()) {
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = YES) |
4 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = YES) |
4 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = YES) |
4 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = YES) |
4 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = YES) |
4 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
5 |
Halted |
0 ms |
0 KB |
- |