Submission #701100

#TimeUsernameProblemLanguageResultExecution timeMemory
701100mychecksedadDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define all(x) x.begin(), x.end()

vector<int> find_subset(int l, int r, vector<int> w) {
    vector<pair<int, int>> a;
    int n = w.size();
    for(int i = 0; i < n; ++i) a.pb({w[i], i});
    sort(all(a));
    if(r < a[0].first){
        return vector<int>(0);
    }
    ll s = 0;
    for(int i = 0; i < n; ++i){
        s += a[i].first;
    }
    if(s < l){
        return vector<int>(0);
    }
    set<int> ans;
    s = 0;

    for(int i = 0; i < n; ++i){
        if(s + a[i].first > r){
            bool ok = 0;
            for(int j = n - 1; j >= n - i - 1; --j){
                ans.insert(a[j].second);
                ans.erase(a[n - j - 1].second);
                s += a[j].first - a[n - j - 1].first;
                if(s >= l && s <= r){
                    ok = 1;
                    break;
                }
            }
            if(!ok) return vector<int>(0);
            break;
        }
        ans.insert(a[i].second);
        s += a[i].first;
        if(s <= r && s >= l) break;
    }
    ll x = 0;
    for(int c: ans) x += w[c];
    assert(c>=l&&c<=r); 
    vector<int> A;
    for(int x: ans) A.pb(x);
    return A;
}

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from molecules.cpp:2:
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:47:12: error: 'c' was not declared in this scope
   47 |     assert(c>=l&&c<=r);
      |            ^