Submission #1256447

#TimeUsernameProblemLanguageResultExecution timeMemory
1256447islam_2010Detecting Molecules (IOI16_molecules)C++20
Compilation error
0 ms0 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> find_subset(int l, int u, vector<int> w){
    int s = 0;
    vector<pair<int, int>> v;
    for(int i = 0; i < n; i++){
        v.push_back({w[i], i});
    }sort(v.begin(), v.end());
    int le = 0;
    for(int r = 0; r < n; r++){
        s += v[r].first;
        while (s>u){
            s -= w[le].first;
        }if(s >= l && s <= u){
            vector<int> ans;
            for(int i = le; i <= r; i++){
                ans.push_back(w[i].second);
            }sort(ans.begin(), ans.end());
            return ans;
        }
    }return {};
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:24: error: 'n' was not declared in this scope
    8 |     for(int i = 0; i < n; i++){
      |                        ^
molecules.cpp:12:24: error: 'n' was not declared in this scope
   12 |     for(int r = 0; r < n; r++){
      |                        ^
molecules.cpp:15:24: error: request for member 'first' in 'w.std::vector<int>::operator[](((std::vector<int>::size_type)le))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   15 |             s -= w[le].first;
      |                        ^~~~~
molecules.cpp:19:36: error: request for member 'second' in 'w.std::vector<int>::operator[](((std::vector<int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   19 |                 ans.push_back(w[i].second);
      |                                    ^~~~~~
molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~