답안 #102042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102042 2019-03-22T00:28:52 Z tim25871014 Detecting Molecules (IOI16_molecules) C++17
컴파일 오류
0 ms 0 KB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> find_subset(int l,int u,vector<int> w){

    vector<int> ans;

    int n=w.size();
    vector<pair<int,int>> wp;
    for(int i=0;i<n;i++)
        wp.push_back({w[i],i});
    sort(wp.begin(),wp.end());

    int sum=0;
    deque<int> sub;
    for(int i=0;i<n;i++){
        sum+=w[i],sub.push_back(wp[i]);
        while(sum>u) sum-=sub.front(),sub.pop_front();
        if(sum<=u && sum>=l) {check=1;break;}
    }
    if(!check) return ans;
    for(auto i:sub) ans.push_back(sub.second);
    return ans;

}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:18:38: error: no matching function for call to 'std::deque<int>::push_back(__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> > >::value_type&)'
         sum+=w[i],sub.push_back(wp[i]);
                                      ^
In file included from /usr/include/c++/7/deque:64:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:68,
                 from molecules.cpp:2:
/usr/include/c++/7/bits/stl_deque.h:1542:7: note: candidate: void std::deque<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::deque<_Tp, _Alloc>::value_type = int]
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_deque.h:1542:7: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> > >::value_type {aka std::pair<int, int>}' to 'const value_type& {aka const int&}'
/usr/include/c++/7/bits/stl_deque.h:1557:7: note: candidate: void std::deque<_Tp, _Alloc>::push_back(std::deque<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::deque<_Tp, _Alloc>::value_type = int]
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_deque.h:1557:7: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> > >::value_type {aka std::pair<int, int>}' to 'std::deque<int>::value_type&& {aka int&&}'
molecules.cpp:20:31: error: 'check' was not declared in this scope
         if(sum<=u && sum>=l) {check=1;break;}
                               ^~~~~
molecules.cpp:20:31: note: suggested alternative: 'clock'
         if(sum<=u && sum>=l) {check=1;break;}
                               ^~~~~
                               clock
molecules.cpp:22:9: error: 'check' was not declared in this scope
     if(!check) return ans;
         ^~~~~
molecules.cpp:22:9: note: suggested alternative: 'clock'
     if(!check) return ans;
         ^~~~~
         clock
molecules.cpp:23:39: error: 'class std::deque<int>' has no member named 'second'; did you mean 'end'?
     for(auto i:sub) ans.push_back(sub.second);
                                       ^~~~~~
                                       end
molecules.cpp:23:14: warning: unused variable 'i' [-Wunused-variable]
     for(auto i:sub) ans.push_back(sub.second);
              ^