#include "molecules.h"
#include <valarray>
#include <vector>
using namespace std;
vector<int> ans;
struct number {
int n;
int index;
bool operator<(const number& other) const {
return n < other.n;
}
};
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
vector<number> numbers;
int total = 0;
for (int i = 0; i < w.size(); i++) {
number num;
num.n = w[i];
num.index = i;
numbers.push_back(num);
}
sort(numbers.begin(),numbers.end());
int bigCount = 0, smallCount = 0;
int big = numbers[n-1].n, small = numbers[0].n;
for (auto [num, ind] : numbers) {
if (num == big) bigCount++;
if (num == small) smallCount++;
}
vector<int> ans1;
vector<int> ans2;
int i = n-1;
while (total < u) {
total += numbers[i].n;
ans1.push_back(numbers[i].index);
if (total >= l && total <= u) {
return ans;
}
}
int lower = 0;
int upper = i;
while (lower < upper) {
total -= numbers[ans1.back()].n;
ans1.pop_back();
ans2.push_back(numbers[lower].index);
total += numbers[lower].index;
lower++;
if (total >= l && total <= u) {
ans1.insert(ans1.end(),ans2.begin(),ans2.end());
return ans1;
}
}
return vector<int>(0);
}
컴파일 시 표준 에러 (stderr) 메시지
molecules.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |