Submission #642550

#TimeUsernameProblemLanguageResultExecution timeMemory
642550rc_catuntaDetecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms212 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,int> ii; vector<int> find_subset(int l, int u, vector<int> w) { vector<ii> v; for(int i=0;i<w.size();i++){ v.push_back(ii(ll(w[i]),i)); } sort(v.begin(),v.end()); // Acumuladas vector<ll>a; a.push_back(v[0].first); for(int i=1;i<v.size();i++){ a.push_back(a[i-1]+v[i].first); } vector<int> res; long long objetivo; int pos; for(int i=0;i<a.size();i++){ if(a[i]>=l and a[i]<=u){ // Es el rango de 0 hasta i for(int k=0;k<=i;k++) res.push_back(v[k].second); return res; } int resl=-1,resu=-1; if(a[i]>=l){ // Objetivo l objetivo = a[i] - l; pos = lower_bound(v.begin(),v.end(),ii(objetivo,0))-v.begin(); if(a[i]-a[pos]>=l and a[i]-a[pos]<=u){ resl=pos+1; resu=i; } if(pos>0){ if(a[i]-a[pos-1]>=l and a[i]-a[pos-1]<=u){ resl=pos; resu=i; } } if(resu>=0 and resl>=0){ for(int k=resl;k<=resu;k++) res.push_back(v[k].second); return res; } } } res.clear(); return res; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
molecules.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=1;i<v.size();i++){
      |                 ~^~~~~~~~~
molecules.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
molecules.cpp:27:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   27 |             for(int k=0;k<=i;k++)
      |             ^~~
molecules.cpp:29:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   29 |                 return res;
      |                 ^~~~~~
#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...