Submission #138370

#TimeUsernameProblemLanguageResultExecution timeMemory
138370arthurconmyDetecting Molecules (IOI16_molecules)C++14
100 / 100
70 ms10356 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(W[i-1].second); cur2 += W[n-i].first; v2.push_back(W[n-i].second); 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 && cur2 >= l) return v2; } return {}; } #ifdef ARTHUR_LOCAL int main() { vector<int> V = find_subset(50,51,{25,26}); 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++)
                  ~^~~~~~~~~~
#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...