제출 #1363885

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

vector<int> find_subset(int l, int u, std::vector<int> w) 
{
	int n = w.size();
	
	vector<pair<int, int>> a;
	for (int i = 0; i < n; i++)
	{
		a.push_back(w[i], i);
	}
	
	sort(a.begin(), a.end());
	int l1 = 0;
    long long sum = 0;

    for (int r = 0; r < n; r++) 
	{
        sum += a[r].first;
        while (sum > u && l1 <= r) 
		{
            sum -= a[l1].first;
            l1++;
        }
        if (sum >= l && sum <= u) {
            vector<int> ans;
            for (int i = l1; i <= r; i++) 
			{
                result.push_back(a[i].second);
            }
            return ans;
        }
    }
    return 0;
}

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:12:28: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, int&)'
   12 |                 a.push_back(w[i], i);
      |                 ~~~~~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note:   candidate expects 1 argument, 2 provided
molecules.cpp:31:17: error: 'result' was not declared in this scope
   31 |                 result.push_back(a[i].second);
      |                 ^~~~~~
molecules.cpp:36:12: error: could not convert '0' from 'int' to 'std::vector<int>'
   36 |     return 0;
      |            ^
      |            |
      |            int