이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <iostream>
using namespace std;
using int64 = long long;
auto impossible = vector<int> {};
vector<int> find_subset(int l, int u, vector<int> w) {
vector<int> sol;
int64 res = 0;
int N = w.size();
vector<int> order(N);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int a, int b){
return w[a] < w[b];
});
for (auto i : order) {
res += w[i];
sol.push_back(i);
if (res >= l)
break;
}
if (res <= u)
return sol;
else if (res < l)
return impossible;
// cerr << "here: " << res << "\n";
int at = 0;
while(at < sol.size()) {
res -= w[sol[at]];
at++;
if (res >= l && res <= u) {
return vector<int>(sol.begin() + at, sol.end());
} else if (res < l) {
return impossible;
}
}
return impossible;
}
// void debug(vector<int> v) {
// for (auto x : v) cerr << x << " "; cerr << "\n";
// }
// int main() {
// debug(find_subset(15, 17, {6, 8, 8, 7}));
// debug(find_subset(14, 15, {5, 5, 6, 6}));
// debug(find_subset(10, 20, {15, 17, 16, 18}));
// return 0;
// }
컴파일 시 표준 에러 (stderr) 메시지
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:41:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | while(at < sol.size()) {
| ~~~^~~~~~~~~~~~
# | 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... |