Submission #348724

#TimeUsernameProblemLanguageResultExecution timeMemory
348724NachoLibreDetecting Molecules (IOI16_molecules)C++14
10 / 100
1 ms384 KiB
#include <bits/stdc++.h>
using namespace std;
#ifndef wambule
#include "molecules.h"
#endif

vector<int> find_subset(int l, int u, vector<int> w) {
    vector<int> dr;
    int n = w.size();
    multiset<int> s;
    unsigned int sm = 0;
    s.insert(0);
    for(int i = n - 1; i >= 0; --i) {
        sm += w[i];
        if(sm <= u) s.insert(sm);
        if(sm >= l) break;
    }
    sm = 0;
    int fl = -1, fr;
    if(*(--s.end()) >= l) fl = 0, fr = *(--s.end());
    for(int i = 0; i < n; ++i) {
        sm += w[i];
        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;
        }
        if(s.size() == n - i + 1) s.erase(--s.end());
    }
    if(fl != -1) {
        sm = 0;
        for(int i = 0; i < n; ++i) {
            sm += w[i];
            if(sm > fl) break;
            dr.push_back(i);
        }
        sm = 0;
        for(int i = n - 1; i >= 0; --i) {
            sm += w[i];
            if(sm > fr) break;
            dr.push_back(i);
        }
    }
    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:15:15: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   15 |         if(sm <= u) s.insert(sm);
      |            ~~~^~~~
molecules.cpp:16:15: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   16 |         if(sm >= l) break;
      |            ~~~^~~~
molecules.cpp:23:15: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   23 |         if(sm >= l) {
      |            ~~~^~~~
molecules.cpp:24:19: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   24 |             if(sm <= u) {
      |                ~~~^~~~
molecules.cpp:31:38: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   31 |         if(it != s.end() && sm + *it <= u) {
      |                             ~~~~~~~~~^~~~
molecules.cpp:35:21: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |         if(s.size() == n - i + 1) s.erase(--s.end());
      |            ~~~~~~~~~^~~~~~~~~~~~
molecules.cpp:41:19: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   41 |             if(sm > fl) break;
      |                ~~~^~~~
molecules.cpp:47:19: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   47 |             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...