Submission #1163100

#TimeUsernameProblemLanguageResultExecution timeMemory
1163100boclobanchatDetecting Molecules (IOI16_molecules)C++20
Compilation error
0 ms0 KiB
#include"molecules.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> find_subset(int l,int u,vector<int> w)
{
	int idx=0;
	vector< pair<int,int> > x;
	for(auto v:w) x.push_back({v,idx++});
	sort(w.begin(),w.end());
	sort(x.begin(),x.end());
	int sum=0;
	for(int i=0;i<w.size()-1;i++)
	{
		sum+=w[i];
		if(sum>=l&&sum<=u)
		{
			vector<int> ans;
			for(int j=0;j<=i;j++) ans.push_back(x[j].second);
			return ans;
		}
		if(sum-w[0]>=l&&sum-w[0]<=u)
		{
			vector<int> ans;
			for(int j=1;j<=i;j++) ans.push_back(x[j].second);
			return ans;
		}
		if(sum-w[0]+w[w.size()-1]>=l&&sum-w[0]+w[w.size()-1]<=u)
		{
			vector<int> ans;
			for(int j=1;j<=i;j++) ans.push_back(x[j].second);
			ans.push_back(x[w.size()-1].second);
			return ans;
		}
		if(sum+w[w.size()-1]>=l&&sum+w[w.size()-1]<=u)
		{
			vector<int> ans;
			for(int j=0;j<=i;j++) ans.push_back(x[j].second);
			ans.push_back(x[w.size()-1]);
			return ans;
		}
	}
	return vector<int>(0);
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:38:38: error: no matching function for call to 'std::vector<int>::push_back(__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type&)'
   38 |                         ans.push_back(x[w.size()-1]);
      |                         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1187: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]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1203: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]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~