#include "molecules.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using i64 = long long;
using d64 = long double;
using pi = pair<int, int>;
using pli = pair<i64, i64>;
using ti = tuple<int, int, int>;
using tli = tuple<i64, i64, i64>;
#define iterall(cont) cont.begin(), cont.end()
#define prec(n) setprecision(n) << fixed
vector<int> find_subset(int l, int u, vector<int> w) {
const int N = w.size();
vector<pli> wei;
for (int i = 0; i < N; i++) wei.emplace_back(w[i], i);
sort(iterall(wei));
vector<int> mp;
for (int i = 0; i < N; i++) mp[wei[i].second] = i;
// prefix sum
vector<i64> ps(N + 1);
for (int i = 1; i <= N; i++) ps[i] = ps[i - 1] + wei[i - 1].first;
function<i64(int, int)> rangeSum = [&ps](int _l, int _r) {
return ps[_r + 1] - ps[_l];
};
function<void(vector<int>&)> sanitize = [&mp](vector<int> &v) {
for(auto &el:v) el = mp[el];
};
for (int iv = 0; iv < N; iv++) {
auto lBound = rangeSum(0, iv);
auto rBound = rangeSum(N - 1 - iv, N - 1);
if (l <= lBound && lBound <= u) {
vector<int> ret;
for (int k = 0; k <= iv; k++) ret.emplace_back(k);
sanitize(ret);
return ret;
}
if (l <= rBound && rBound <= u) {
vector<int> ret;
for (int k = N - 1 - iv; k <= N - 1; k++) ret.emplace_back(k);
sanitize(ret);
return ret;
}
if (lBound <= l && u <= rBound) {
for (int j = 0; j < N - 1 - iv; j++) {
if (l <= rangeSum(j, j + iv) && rangeSum(j, j + iv) <= u) {
vector<int> ret;
for (int k = j; k <= j + iv; k++) ret.emplace_back(k);
sanitize(ret);
return ret;
}
}
}
}
return vector<int>();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |