이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "molecules.h"
#include<bits/stdc++.h>
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
long long int sum=0;
vector<int>ans;
vector<pair<long long int,int> >arr;
int n=w.size();
for(int i=0;i<w.size();i++){
arr.push_back({w[i],i});
}
sort(arr.begin(),arr.end());
if(arr[0].first>u){
return ans;
}else if(arr[0].first>=l and arr[0].first<=u){
ans.push_back(arr[0].second);
return ans;
}else{
if(arr[n-1].first>=l and arr[n-1].first<=u){
ans.push_back(arr[n-1].second);
return ans;
}else{
int ti1=0;
int ti2=-1;
long long int sum=0;
for(int i=0;i<n;i++){
sum=sum+arr[i].first;
if(sum<l){
ti1=i;
}else if(sum>=l and sum<=u){
for(int j=0;j<=i;j++){
ans.push_back(arr[j].second);
}
return ans;
}else{
ti2=i;
break;
}
}
if(ti2==-1){
return ans;
}else{
long long int sum1=0;
for(int i=n-1;i>=(n-ti1-1);i--){
sum1=sum1+arr[i].first;
}
if(sum1<l){
return ans;
}
int j=n-1;
sum=sum-arr[ti2].first;
for(int i=ti1;i>=0;i--){
sum=sum+arr[j].first-arr[i].first;
if(sum>=l and sum<=u){
for(int k=0;k<i;k++){
ans.push_back(arr[k].second);
}
for(int k=j;k<=(n-1);k++){
ans.push_back(arr[k].second);
}
return ans;
}
j--;
}
}
}
}
for(int i=0;i<w.size();i++){
if(w[i]<=u){
sum=sum+w[i];
ans.push_back(i);
}
if(sum>=l and sum<=u){
break;
}
}
if(sum>=l and sum<=u){
return ans;
}else{
ans.clear();
return ans;}
}
/*
int main() {
int n, l, u;
assert(3 == scanf("%d %d %d", &n, &l, &u));
std::vector<int> w(n);
for (int i = 0; i < n; i++)
assert(1 == scanf("%d", &w[i]));
std::vector<int> result = find_subset(l, u, w);
printf("%d\n", (int)result.size());
for (int i = 0; i < (int)result.size(); i++)
printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}
*/
컴파일 시 표준 에러 (stderr) 메시지
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:12:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int i=0;i<w.size();i++){
| ~^~~~~~~~~
molecules.cpp:71:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i=0;i<w.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... |