제출 #434872

#제출 시각아이디문제언어결과실행 시간메모리
434872sikamax2019Detecting Molecules (IOI16_molecules)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; typedef long long ll; typedef pair <ll, int> pii; vector <int> find_subset (int l, int u, vector <int> w) { int n = w.size(); vector <pii> v; for (int i = 0; i < n; ++i) { v.push_back({(w[i], i)}); } sort(v.begin(), v.end()); ll sum = 0; vector <int> r; for (int i = 0, j = 0; j < n; ++j) { sum += v[j].first; while (sum > u) { sum -= v[i++].first; } if (sum >= l) { for (int k = i; k <= j; ++k) { r.push_back(v[k].second); } break; } } return r; }

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:13:28: error: no matching function for call to 'std::vector<std::pair<long long int, int> >::push_back(<brace-enclosed initializer list>)'
   13 |     v.push_back({(w[i], i)});
      |                            ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 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)
      |                 ~~~~~~~~~~~~~^~~