#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<ll, int> reached;
reached[0] = -1;
for (auto &[num, i]: nums) {
vpll toadd;
for (auto it = reached.cbegin(); it != reached.cend();) {
if (it->first < l - tot) {
reached.erase(it++);
} else {
ll k = it->first + num;
if (reached.find(k) == reached.end()) {
if (k > u) {
break;
}
toadd.emplace_back(k, i);
}
it++;
}
}
for (auto &[num, i]: toadd) {
reached[num] = i;
}
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 |
0 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
0 ms |
256 KB |
OK (n = 1, answer = YES) |
4 |
Runtime error |
567 ms |
65540 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
552 ms |
65540 KB |
Execution killed with signal 9 |
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 |
0 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
0 ms |
256 KB |
OK (n = 1, answer = YES) |
4 |
Runtime error |
567 ms |
65540 KB |
Execution killed with signal 9 |
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 |
0 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
0 ms |
256 KB |
OK (n = 1, answer = YES) |
4 |
Runtime error |
567 ms |
65540 KB |
Execution killed with signal 9 |
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 |
0 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
0 ms |
256 KB |
OK (n = 1, answer = YES) |
4 |
Runtime error |
567 ms |
65540 KB |
Execution killed with signal 9 |
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 |
0 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
0 ms |
256 KB |
OK (n = 1, answer = YES) |
4 |
Runtime error |
567 ms |
65540 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |