Submission #1040699

#TimeUsernameProblemLanguageResultExecution timeMemory
1040699LaMatematica14Detecting Molecules (IOI16_molecules)C++17
100 / 100
77 ms18420 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> fine(multimap<long long, int> a) {
    vector<int> r(a.size()); int n = 0;
    for(pair<int, int> i : a) r[n++] = i.second;
    return r;
}

vector<int> find_subset(int l, int u, vector<int> w) {
    vector<pair<long long, int>> wn(w.size());
    for (int i = 0; i < w.size(); i++) wn[i] = {w[i], i};
    sort(wn.begin(), wn.end());
    multimap<long long, int> in;
    long long tot = 0, larg = 0;
    for (int i = 0; i < wn.size() && tot+wn[i].first <= u; i++) {
        tot += wn[i].first; in.insert(wn[i]);
        if (tot >= l) return fine(in);
        larg = i;
    }
    for (int i = larg+1; i < wn.size() && tot < l; i++) {
        if (in.lower_bound(tot+wn[i].first-(long long)u) != in.end()) {
            long long aus = tot;
            tot -= (*in.lower_bound(tot+wn[i].first-(long long)u)).first; 
            tot += wn[i].first;
            in.erase(in.lower_bound(aus+wn[i].first-(long long)u));
            in.insert(wn[i]);
        }
        if (tot >= l) return fine(in);
    }
    vector<int> a(0);
    return a;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < w.size(); i++) wn[i] = {w[i], i};
      |                     ~~^~~~~~~~~~
molecules.cpp:16:23: 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]
   16 |     for (int i = 0; i < wn.size() && tot+wn[i].first <= u; i++) {
      |                     ~~^~~~~~~~~~~
molecules.cpp:21:28: 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]
   21 |     for (int i = larg+1; i < wn.size() && tot < l; 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...