Submission #344807

#TimeUsernameProblemLanguageResultExecution timeMemory
344807ogibogi2004Detecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
#include <cstdio> #include <vector> #include <cassert> #include "molecules.h" #include "molecules.h" #include <bits/stdc++.h> using namespace std; #define ll long long vector<int> find_subset(int l, int u, vector<int> w) { ll t=0; vector<pair<ll,ll> >da; for(int i=0;i<w.size();i++) { da.push_back({w[i],i}); } sort(da.begin(),da.end()); ll j=-1; for(ll i=0;i<da.size();i++) { t+=da[i].first; if(t>u)break; j=i; } if(j==-1)return vector<int>(0); t=0; for(ll i=0;i<=j;i++) { t+=da[i].first; } ll f=0; for(int i=da.size()-1;i>=da.size()-j-1;i--) { f+=da[i].first; } if(t>u||f<l) { return vector<int>(0); } set<int>ivan; set<int>not_taken; for(ll i=0;i<=j;i++)ivan.insert(i); for(ll i=j+1;i<da.size();i++)not_taken.insert(i); while(t<l) { ll i1=(*ivan.begin()); ll i2=(*not_taken.rbegin()); ivan.erase(i1); not_taken.insert(i2); ivan.insert(i2); not_taken.erase(i1); t+=da[i2].first-da[i1].first; } vector<int>ret; for(auto of:ivan) { ret.push_back(da[of].second); } sort(ret.begin(),ret.end()); return ret; } 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]); }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=0;i<w.size();i++)
      |                 ~^~~~~~~~~
molecules.cpp:23:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(ll i=0;i<da.size();i++)
      |                ~^~~~~~~~~~
molecules.cpp:36:25: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   36 |  for(int i=da.size()-1;i>=da.size()-j-1;i--)
      |                        ~^~~~~~~~~~~~~~~
molecules.cpp:47:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(ll i=j+1;i<da.size();i++)not_taken.insert(i);
      |               ~^~~~~~~~~~
/tmp/ccEZ4EWs.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccsGKbvH.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status