Submission #348757

#TimeUsernameProblemLanguageResultExecution timeMemory
348757NachoLibreDetecting Molecules (IOI16_molecules)C++14
100 / 100
105 ms13660 KiB
#include <bits/stdc++.h> using namespace std; #ifndef wambule #include "molecules.h" #endif vector<int> find_subset(int l, int u, vector<int> wi) { int n = wi.size(); vector<pair<int, int> > w; for(int i = 0; i < n; ++i) { w.push_back({wi[i], i}); } sort(w.begin(), w.end()); vector<int> dr; multiset<int> s; unsigned int sm = 0; int fl = -1, fr; for(int i = n - 1; i >= 0; --i) { sm += w[i].first; if(sm >= l) { if(sm <= u) { fl = 0; fr = sm; } break; } s.insert(sm); } sm = 0; for(int i = 0; i < n; ++i) { if(i + (int)s.size() == n) s.erase(--s.end()); sm += w[i].first; if(sm >= l) { if(sm <= u) { fl = sm; fr = 0; } break; } auto it = s.lower_bound(l - sm); if(it != s.end() && sm + *it <= u) { fl = sm; fr = *it; break; } } if(fl != -1) { sm = 0; for(int i = 0; i < n; ++i) { sm += w[i].first; if(sm > fl) break; dr.push_back(w[i].second); } sm = 0; for(int i = n - 1; i >= 0; --i) { sm += w[i].first; if(sm > fr) break; dr.push_back(w[i].second); } } assert((int)dr.size() <= n && (dr.size() || fl == -1)); return dr; } #ifdef wambule int main() { ios::sync_with_stdio(0); cin.tie(0); return 0; } #endif

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:20:15: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   20 |         if(sm >= l) {
      |            ~~~^~~~
molecules.cpp:21:19: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   21 |             if(sm <= u) {
      |                ~~~^~~~
molecules.cpp:33:15: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   33 |         if(sm >= l) {
      |            ~~~^~~~
molecules.cpp:34:19: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   34 |             if(sm <= u) {
      |                ~~~^~~~
molecules.cpp:41:38: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   41 |         if(it != s.end() && sm + *it <= u) {
      |                             ~~~~~~~~~^~~~
molecules.cpp:51:19: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   51 |             if(sm > fl) break;
      |                ~~~^~~~
molecules.cpp:57:19: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   57 |             if(sm > fr) break;
      |                ~~~^~~~
#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...