제출 #297777

#제출 시각아이디문제언어결과실행 시간메모리
297777emnikDetecting Molecules (IOI16_molecules)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;

typedef long long ll;
#define pb push_back
#define all(x) begin(x), end(x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

std::vector<int> find_subset(int l, int r, vector<int> W){
    vector<int> a,b;
    vector<pair<int, int>> Pair;


    for(int i=0; i < (int)W.size(); i++){
        Pair.pb({W[i], i});
    }
    sort(Pair.begin(), Pair.end());
    ll sum=0, x=0, flag=0;
    for(int i=0; i < (int)Pair.size(); i++){
       if(sum < l){
      	  sum += (ll)Pair[i].first;
      	  a.pb({Pair[i].first, Pair[i].second});
       }
       if(sum > r){
	       	sum -= (ll)Pair[x].first;
	       	x++;
       }

       if(sum >= l && sum <= r){
	       flag=1;
	       break;
       }
    }


    for(int i=x; i < (int)a.size(); i++){
    	b.pb(a[i].second);
    }
    return b;
}

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:23:46: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   23 |          a.pb({Pair[i].first, Pair[i].second});
      |                                              ^
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1184: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]'
 1184 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1184:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1184 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1200: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]'
 1200 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1200:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1200 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
molecules.cpp:38:16: error: request for member 'second' in 'a.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'}
   38 |      b.pb(a[i].second);
      |                ^~~~~~