제출 #1196672

#제출 시각아이디문제언어결과실행 시간메모리
1196672amanthabandDetecting Molecules (IOI16_molecules)C++20
컴파일 에러
0 ms0 KiB
#include "molecules.h" #include <vector> #include <algorithm> using namespace std; vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); vector<pair<int,int>> in; for (int i = 0; i < n; i++) { in.push_back({w[i],i}); } sort(in.begin(),in.end()); int sum = 0; int left = 0,right = 0; while (right < n) { sum+= w[right].first; if(sum>u){ sum-=w[left].first; --left; } if(sum>=l && sum<=u){ vector<int> ans; for (int i = left; i < right; i++) { ans.push_back({w[i].second}); } return ans; } } return {}; }

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:24:24: error: request for member 'first' in 'w.std::vector<int>::operator[](((std::vector<int>::size_type)right))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   24 |         sum+= w[right].first;
      |                        ^~~~~
molecules.cpp:26:26: error: request for member 'first' in 'w.std::vector<int>::operator[](((std::vector<int>::size_type)left))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   26 |             sum-=w[left].first;
      |                          ^~~~~
molecules.cpp:34:37: 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'}
   34 |                 ans.push_back({w[i].second});
      |                                     ^~~~~~
molecules.cpp:34:30: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   34 |                 ans.push_back({w[i].second});
      |                 ~~~~~~~~~~~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
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
      |         ^~~~