| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1299901 | tuncay_pasha | Detecting Molecules (IOI16_molecules) | C++20 | 34 ms | 4132 KiB |
#include "molecules.h"
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
// Keep the standard signature using 'int' to match the header
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
// Store pair {value, original_index}
vector<pair<int, int>> v;
for (int i = 0; i < n; ++i) {
v.push_back({w[i], i});
}
sort(v.begin(), v.end());
int lp = 0, rp = 0;
// Use long long for the sum to prevent overflow
long long cur = v[0].first;
while (lp < n && rp < n) {
if (l <= cur && cur <= u) {
vector<int> ans;
// FIX: Use v[i].second to get the ORIGINAL index
for (int i = lp; i <= rp; ++i) {
ans.push_back(v[i].second);
}
return ans;
}
else if (cur < l) {
if (rp + 1 >= n) break;
rp++;
cur += v[rp].first;
}
else { // cur > u
// Important check: don't let lp cross rp
if (lp > rp) break;
cur -= v[lp].first;
lp++;
// Edge case: if window becomes empty, reset to next element
if (lp > rp && lp < n) {
rp = lp;
cur = v[lp].first;
}
}
}
return {};
}
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... | ||||
