Submission #138368

#TimeUsernameProblemLanguageResultExecution timeMemory
138368arthurconmyDetecting Molecules (IOI16_molecules)C++14
9 / 100
2 ms380 KiB
#include <bits/stdc++.h> #ifndef ARTHUR_LOCAL #include "molecules.h" #endif using namespace std; using ll = long long; vector<int> find_subset(int u, int d, vector<int> W_raw) { int n = W_raw.size(); int l = ll(u); int r = ll(d); vector<pair<ll,int>> W; for(int i=0; i<n; i++) { W.push_back(make_pair(ll(W_raw[i]),i)); } sort(W.begin(),W.end()); ll cur1=0; ll cur2=0; vector<int> v1; vector<int> v2; bool works=0; for(int i=1; i<=n; i++) { cur1 += W[i-1].first; v1.push_back(i-1); cur2 += W[n-i].first; v2.push_back(n-i); if(cur1 >= l && cur1 <= r) { // return cur1 things return v1; } if(cur2 >= l && cur2 <= r) { return v2; } if(cur1 < l && cur2 > r) // LOOKS DODGY, PROBABLY IS RIGHT { works=1; break; } } if(!works) return {}; // definitely at this point for(int i=0; i<v1.size(); i++) { cur2 -= ll(W_raw[v2[v1.size()-i-1]]); cur2 += ll(W_raw[v1[i]]); // after this update, cur2 decreases by at most v2[v1.size()-i-1]=v1[i]; if(cur2 <= r) return v2; } } #ifdef ARTHUR_LOCAL int main() { vector<int> V = find_subset(50,51,{16,16,17,17,17}); cout << V.size() << endl; for(auto v:V) cout << v << " "; } #endif

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:59:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<v1.size(); i++)
                  ~^~~~~~~~~~
molecules.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...