Submission #413850

#TimeUsernameProblemLanguageResultExecution timeMemory
413850illyakrDetecting Molecules (IOI16_molecules)C++14
100 / 100
105 ms19600 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long

vector<pair<ll, ll> > a;
multiset<pair<ll, ll> > ok, bad;
ll now = 0;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    for (ll i = 0; i < w.size(); i++)
        a.push_back({w[i], i});
    sort(a.begin(), a.end(), [](pair<ll, ll> q, pair<ll, ll> w) {
         return q.first < w.first;
    });
    for (auto [i, j] : a) {
        if (now + i <= u) {
            now += i;
            ok.insert({i, j});
        } else {
            bad.insert({i, j});
        }
    }
    while (true) {
        if (l <= now && now <= u) {
            vector<int> res;
            for (auto [i, j] : ok)
                res.push_back(j);
            return res;
        }
        if (bad.empty() || ok.empty())break;
        auto have = *ok.begin();
        auto want = *(--bad.end());
        ok.erase(ok.begin());
        bad.erase(--bad.end());

        if (have.first >= want.first)break;
        now -= have.first;
        now += want.first;
        ok.insert(want);
    }
    return {};
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:10:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (ll i = 0; i < w.size(); i++)
      |                    ~~^~~~~~~~~~
molecules.cpp:15:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   15 |     for (auto [i, j] : a) {
      |               ^
molecules.cpp:26:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   26 |             for (auto [i, j] : ok)
      |                       ^
#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...