Submission #1037159

#TimeUsernameProblemLanguageResultExecution timeMemory
1037159vjudge1Detecting Molecules (IOI16_molecules)C++17
100 / 100
39 ms9420 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; #define ll long long std::vector<int> find_subset(int l, int u, std::vector<int> w) { vector<int> ans; vector<pair<ll, ll>> v; ll n=w.size(); for(int i=0; i<w.size(); i++){ v.push_back({w[i], i}); } sort(v.begin(), v.end()); ll i=0, j=0, sum=0; while(j<n && i<n){ while(j<n && sum<l){ sum+=v[j++].first; } if(sum>=l && sum<=u && v[j-1].first-v[i].first<=u-l){ for(int k=i; k<j; k++){ ans.push_back(v[k].second); //cout<<v[j].second<<' '; } return ans; } sum-=v[i].first; if(sum>=l && sum<=u && v[j-1].first-v[i+1].first<=u-l){ for(int k=i+1; k<j; k++){ ans.push_back(v[k].second); //cout<<v[j].second<<' '; } return ans; } i++; } return ans; } /* [] 2 14 1 5 6 7 8 1 2 3 3 4 4 */

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:9:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for(int i=0; i<w.size(); i++){
      |                  ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...