이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
using ll = long long;
const ll INF = 1e18;
vector<int> find_subset(int l1, int u1, vector<int> w2) {
vector<pair<ll, int>> w;
ll l = l1, u = u1;
for(int i = 0; i < w2.size(); i++) {
w.push_back({w2[i], i});
}
sort(w.begin(), w.end());
set<array<ll, 2>, greater<array<ll, 2>>> s;
multiset<pair<ll, int>> w1;
int n = w.size();
s.insert({0, 0});
ll ans = 0;
for(int i = 0; i < n; i++) {
if(w[i].first > u) continue;
w1.insert({w[i].first, w[i].second});
int k = w[i].first;
auto it = s.lower_bound({u-k, INF});
if(it != s.end()) {
ans = max(ans, k+(*it)[0]);
s.insert({(*it)[0]+k, k});
}
if(it != s.end() && (*it)[0] != 0) s.insert({w[i].first, w[i].first});
}
if(ans < l) return {};
vector<int> res;
while(ans != 0) {
auto it = s.lower_bound({ans, INF});
ll curr = (*it)[1];
ans -= curr;
auto it1 = w1.lower_bound({curr, INF});
res.push_back((*it1).second);
w1.erase(it1);
}
sort(res.begin(), res.end());
return res;
}
/*
int main()
{
int l = 16, u = 16;
vector<int> v = {5, 5, 5, 1};
auto ans = find_subset(l, u, v);
for(auto it : ans) {
cout << it << ' ';
}
}*/
컴파일 시 표준 에러 (stderr) 메시지
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:11:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(int i = 0; i < w2.size(); i++) {
| ~~^~~~~~~~~~~
# | 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... |