답안 #240240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240240 2020-06-18T23:34:38 Z Amy313 Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> find_subset(int l, int u, vector<int> w)
{
    vector<pair<int, int> >M;
    vector<int> A;
    int s, n = w.size(), c;
    for(int i=0; i<n; i++)
    {
        M.push_back(make_pair(W[i], i+1));
    }
    sort(M.begin(), M.end());
    A.clear();
    if(M[0].first>u)
	{
		return A;
	}
    for(int i=n-1; i>=0; i--)
    {
        s = M[i].first;
        c =0;
        A.push_back(M[i].second);
        if(s<l)
        {
            for(int j=0; j<w.size(); j++)
            {
            	s+=M[j].first;
            	A.push_back(M[j].second);
            	if(s>=l and s<=u)
				{
					c = 1;
					break;
				}
				else
				{
					if(s>u)
					{
						A.erase(A.size()-1);
						break;
					}
				}
            }
            if(c==1)
			{
				break;
			}
        }
        else
		{
			if(s<=u)
			{
				break;
			}
		}
    }
    return A;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:11:31: error: 'W' was not declared in this scope
         M.push_back(make_pair(W[i], i+1));
                               ^
molecules.cpp:26:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=0; j<w.size(); j++)
                          ~^~~~~~~~~
molecules.cpp:39:25: error: no matching function for call to 'std::vector<int>::erase(std::vector<int>::size_type)'
       A.erase(A.size()-1);
                         ^
In file included from /usr/include/c++/7/vector:64:0,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:1179:7: note: candidate: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const int*]
       erase(const_iterator __position)
       ^~~~~
/usr/include/c++/7/bits/stl_vector.h:1179:7: note:   no known conversion for argument 1 from 'std::vector<int>::size_type {aka long unsigned int}' to 'std::vector<int>::const_iterator {aka __gnu_cxx::__normal_iterator<const int*, std::vector<int> >}'
/usr/include/c++/7/bits/stl_vector.h:1206:7: note: candidate: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const int*]
       erase(const_iterator __first, const_iterator __last)
       ^~~~~
/usr/include/c++/7/bits/stl_vector.h:1206:7: note:   candidate expects 2 arguments, 1 provided