Submission #330171

# Submission time Handle Problem Language Result Execution time Memory
330171 2020-11-24T05:41:41 Z saarthak Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "molecules.h"

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
	int n = w.size();
	
	if(l == u) {
		if(l%w[0] == 0 && l/w[0] <= n)
			return std::vector<int>(l/w[0], w[0]);			//all weights equal
		
	else if(l == u)
		return std::vector<int>();						//no subarray found
	
	
	int total_weight = 0, i = 0;
	std::queue<int> indices;
	
	struct weights {
		int wt;
		int idx;
	} wts[n];
	
	for(int i = 0; i < n; i++)
		wts[i] = {w[i], i};
	
	std::sort(wts, wts + n);
	
	while(total_weight < l) {
		total_weight += wts[i].wt;
		indices.push(wts[i].idx);
		i++;
	}
	i = 0;
	while(total_weight > u) {
		total_weight -= wts[i].wt;
		indices.pop();
	}
	
	if(total_weight < l || total_weight > u) return std::vector<int>();		//no subarray found
	
	std::vector<int> ans(indices.size());
  	i = 0;
	while(!indices.empty()) {
		ans[i++] = indices.front();
		indices.pop();
	}
	
	return ans;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:49:1: error: expected '}' at end of input
   49 | }
      | ^
molecules.cpp:4:64: note: to match this '{'
    4 | std::vector<int> find_subset(int l, int u, std::vector<int> w) {
      |                                                                ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = find_subset(int, int, std::vector<int>)::weights*; _Iterator2 = find_subset(int, int, std::vector<int>)::weights*]':
/usr/include/c++/9/bits/stl_algo.h:81:17:   required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1920:34:   required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1952:38:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1967:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:4867:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = find_subset(int, int, std::vector<int>)::weights*]'
molecules.cpp:26:24:   required from here
/usr/include/c++/9/bits/predefined_ops.h:43:23: error: no match for 'operator<' (operand types are 'find_subset(int, int, std::vector<int>)::weights' and 'find_subset(int, int, std::vector<int>)::weights')
   43 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:915:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)'
  915 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:915:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:43:23: note:   'find_subset(int, int, std::vector<int>)::weights' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
   43 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:922:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)'
  922 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:922:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:43:23: note:   'find_subset(int, int, std::vector<int>)::weights' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
   43 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_less_iter::operator()(_Value&, _Iterator) const [with _Value = find_subset(int, int, std::vector<int>)::weights; _Iterator = find_subset(int, int, std::vector<int>)::weights*]':
/usr/include/c++/9/bits/stl_algo.h:1827:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Val_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1854:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1884:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1970:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:4867:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = find_subset(int, int, std::vector<int>)::weights*]'
molecules.cpp:26:24:   required from here
/usr/include/c++/9/bits/predefined_ops.h:90:22: error: no match for 'operator<' (operand types are 'find_subset(int, int, std::vector<int>)::weights' and 'find_subset(int, int, std::vector<int>)::weights')
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:915:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)'
  915 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:915:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   'find_subset(int, int, std::vector<int>)::weights' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:922:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)'
  922 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:922:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   'find_subset(int, int, std::vector<int>)::weights' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = find_subset(int, int, std::vector<int>)::weights*; _Value = find_subset(int, int, std::vector<int>)::weights]':
/usr/include/c++/9/bits/stl_heap.h:133:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Distance = long int; _Tp = find_subset(int, int, std::vector<int>)::weights; _Compare = __gnu_cxx::__ops::_Iter_less_val]'
/usr/include/c++/9/bits/stl_heap.h:237:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Distance = long int; _Tp = find_subset(int, int, std::vector<int>)::weights; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_heap.h:342:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1671:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1932:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1947:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:1967:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = find_subset(int, int, std::vector<int>)::weights*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:4867:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = find_subset(int, int, std::vector<int>)::weights*]'
molecules.cpp:26:24:   required from here
/usr/include/c++/9/bits/predefined_ops.h:65:22: error: no match for 'operator<' (operand types are 'find_subset(int, int, std::vector<int>)::weights' and 'find_subset(int, int, std::vector<int>)::weights')
   65 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:915:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)'
  915 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:915:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:65:22: note:   'find_subset(int, int, std::vector<int>)::weights' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
   65 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:922:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)'
  922 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:922:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:65:22: note:   'find_subset(int, int, std::vector<int>)::weights' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
   65 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h: At global scope:
/usr/include/c++/9/bits/stl_algobase.h:123:5: error: 'void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = find_subset(int, int, std::vector<int>)::weights*; _ForwardIterator2 = find_subset(int, int, std::vector<int>)::weights*]', declared using local type 'find_subset(int, int, std::vector<int>)::weights', is used but never defined [-fpermissive]
  123 |     iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
      |     ^~~~~~~~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:49:1: warning: control reaches end of non-void function [-Wreturn-type]
   49 | }
      | ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39