제출 #101707

#제출 시각아이디문제언어결과실행 시간메모리
101707coldEr66Detecting Molecules (IOI16_molecules)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #include "molecules.h" #define SZ(a) (int)a.size() #define ALL(a) a.begin(),a.end() #define X first #define Y second std::vector<int> find_subset(int l, int u, std::vector<int> w) { vector<int> ret; vector<pair<int,int> > tmp; for (int i=0;i<SZ(w);i++) tmp.emplace_back(w[i],i); sort(ALL(tmp)); long long sum = 0; int L = 0, R = 0; for (;L<SZ(w);L++) { while (sum < l && R < SZ(w)) sum += tmp[R++].X; if (l <= sum && sum <= u) { for (int i=L;i<=R;i++) ret.emplace(tmp[i].Y); break; } if (L < R) sum -= w[L].X; } return ret; }

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:20:50: error: no matching function for call to 'std::vector<int>::emplace(int&)'
       for (int i=L;i<=R;i++) ret.emplace(tmp[i].Y);
                                                  ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from molecules.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:997:2: note: candidate: template<class ... _Args> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::emplace(std::vector<_Tp, _Alloc>::const_iterator, _Args&& ...) [with _Args = {_Args ...}; _Tp = int; _Alloc = std::allocator<int>]
  emplace(const_iterator __position, _Args&&... __args)
  ^~~~~~~
/usr/include/c++/7/bits/stl_vector.h:997:2: note:   template argument deduction/substitution failed:
molecules.cpp:7:11: note:   cannot convert 'tmp.std::vector<std::pair<int, int> >::operator[](((std::vector<std::pair<int, int> >::size_type)i)).std::pair<int, int>::second' (type 'int') to type 'std::vector<int>::const_iterator {aka __gnu_cxx::__normal_iterator<const int*, std::vector<int> >}'
 #define Y second
molecules.cpp:20:49: note: in expansion of macro 'Y'
       for (int i=L;i<=R;i++) ret.emplace(tmp[i].Y);
                                                 ^
molecules.cpp:6:11: error: request for member 'first' in 'w.std::vector<int>::operator[](((std::vector<int>::size_type)L))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}'
 #define X first
           ^
molecules.cpp:23:28: note: in expansion of macro 'X'
     if (L < R) sum -= w[L].X;
                            ^