이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lint long long int
#define pb push_back
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w){
vector<pair<int, int>> v;
for(int i = 0; i < w.size(); i ++){
v.pb({w[i], i});
}
// sort(w.begin(), w.end());
sort(v.begin(), v.end());
int ll = 0, rr = 0;
// int sum = w[0];
int sum = v[0].first;
bool check = true;
while(check){
if(ll > rr){check = false; break;}
// else if(ll < 0){check = false; break;}
else if(rr > w.size()-1){check = false; break;}
else if(sum <= u && sum >= l){break;}
else if(sum > u){
// sum-= w[ll];
sum -= v[ll].first;
ll++;
}
else if(sum < l){
rr++;
// sum+=w[rr];
sum+=v[rr].first;
}
// cout << ll << " " << rr << endl;
}
vector<int> ans;
if(!check){return ans;}
else{
for(int i = ll; i <= rr; i ++){
// ans.pb(w[i]);
ans.pb(v[i].second);
}
sort(ans.begin(), ans.end());
return ans;
}
}
// int main(){
// vector<int> temp;
// // temp = find_subset(15, 17, {6, 8, 8, 7});
// // temp = find_subset(10, 20, {15, 17, 16, 18});
// temp = find_subset(14, 15, {1, 2, 3, 4, 4});
// // temp = find_subset(16, 16, {6, 8, 8, 7});
// for(auto i : temp){cout << i << " ";} cout << endl;
// }
컴파일 시 표준 에러 (stderr) 메시지
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for(int i = 0; i < w.size(); i ++){
| ~~^~~~~~~~~~
molecules.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | else if(rr > w.size()-1){check = false; break;}
| ~~~^~~~~~~~~~~~
# | 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... |