Submission #831331

#TimeUsernameProblemLanguageResultExecution timeMemory
831331SupersonicDetecting Molecules (IOI16_molecules)C++14
100 / 100
42 ms9476 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; std::vector<int> find_subset(int l, int u, std::vector<int> w) { ll n=w.size(); ll ls[n];ll rs[n]; vector<pair<ll,ll>> s; for(ll i=0;i<n;i++)s.push_back({w[i],i}); sort(s.begin(),s.end()); ls[0]=s[0].first;rs[0]=s[n-1].first; ll b=-1; if(ls[0]<=l&&u<=rs[0])b=0; if(ls[0]>=l&&ls[0]<=u)b=0; if(rs[0]>=l&&rs[0]<=u)b=0; for(ll i=1;i<n;i++){ ls[i]=ls[i-1]+s[i].first;rs[i]=rs[i-1]+s[n-1-i].first; if(ls[i]<=l&&u<=rs[i])b=i; if(ls[i]>=l&&ls[i]<=u)b=i; if(rs[i]>=l&&rs[i]<=u)b=i; //cerr<<ls[i]<<' '<<rs[i]<<endl; } //cerr<<b<<endl; if(b==-1)return {}; vector<pair<ll,ll>> rr; ll lp=0; for(ll i=0;i<=b;i++){rr.push_back(s[i]);lp+=s[i].first;} ll ci=0; ll ib=b; while(lp<l){ if(ci==rr.size())exit(1); if(s.size()==b)exit(1); auto y=s.back();s.pop_back(); lp-=rr[ci].first;lp+=y.first; rr[ci]=y; if(lp>=l)break; ci++; } vector<int> r; for(auto i:rr)r.push_back(i.second); return r; } //6 7 8 8

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:31:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |       if(ci==rr.size())exit(1);
      |          ~~^~~~~~~~~~~
molecules.cpp:32:18: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   32 |       if(s.size()==b)exit(1);
      |          ~~~~~~~~^~~
molecules.cpp:29:8: warning: unused variable 'ib' [-Wunused-variable]
   29 |     ll ib=b;
      |        ^~
#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...