Submission #770738

#TimeUsernameProblemLanguageResultExecution timeMemory
770738kirakaminski968Detecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include "molecules.h" #include<bits/stdc++.h> using namespace std; vector<int> find_subset(int l, int u, int[] w){ vector<pair<long long,int>> vec; int n = w.size(); for(int i = 0;i<n;++i) vec.push_back({w[i],i}); sort(vec.begin(),vec.end()); int r = -1; long long sum = 0; for(int i = 0;i<n;++i){ while(r+1 < n && sum < l){ r++; sum += vec[r].first; } if(l <= sum && sum <= u){ vector<int> ans; for(int j = i;j<=r;++j) ans.push_back(vec[j].second); return ans; } } return vector<int>(0); }

Compilation message (stderr)

molecules.cpp:4:45: error: expected ',' or '...' before 'w'
    4 | vector<int> find_subset(int l, int u, int[] w){
      |                                             ^
molecules.cpp: In function 'std::vector<int> find_subset(int, int, int*)':
molecules.cpp:6:11: error: 'w' was not declared in this scope
    6 |   int n = w.size();
      |           ^
molecules.cpp:7:48: error: no matching function for call to 'std::vector<std::pair<long long int, int> >::push_back(<brace-enclosed initializer list>)'
    7 |   for(int i = 0;i<n;++i) vec.push_back({w[i],i});
      |                                                ^
In file included from /usr/include/c++/10/vector:67,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, int> >::value_type&&' {aka 'std::pair<long long int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~