Submission #299132

# Submission time Handle Problem Language Result Execution time Memory
299132 2020-09-14T13:54:31 Z azatega Detecting Molecules (IOI16_molecules) C++11
Compilation error
0 ms 0 KB
#include "molecules.h"
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long

vector<int> find_subset(int l, int u, vector<int> w) {
	vector<pair<ll, int>> new_w;
    vector<int> bl;

	ll tot_sum = 0;
	for(int i = 0; i < w.size(); i++){
		tot_sum += w[i];
		new_w.push_back({w[i], i});
	}

	sort(new_w.begin(), new_w.end());

	if(tot_sum < l || new_w[0] > u)
		return bl;

    ll currsum = 0;
    int tot_sum_idx = 0;

    for(int i = 0; i < new_w.size(); i++){
    	currsum += new_w[i].first;
    	while(tot_sum_idx <= i || (tot_sum_idx < new_w.size() && tot_sum+currsum > u)){
    		tot_sum -= new_w[tot_sum_idx].first;
    		tot_sum_idx++;
    	}

    	if(tot_sum + currsum >= l && tot_sum + currsum <= u){
    		vector<int> res;
			for(int x = 0; x <= i; x++)
				res.push_back(new_w[x].second);
			for(int x = tot_sum_idx; x < new_w.size(); x++)
				res.push_back(new_w[x].second);
			
			return res;
    	}
    }

    return bl;
}

/*int main(){
	int n, l, u;
	vector<int> niz;
	cin >> n >> l >> u;
	
	niz.resize(n);
	for(int i = 0; i < n; i++)
		cin >> niz[i];
	vector<int> rs = find_subset(l, u, niz);
	for(int i = 0; i < rs.size(); i++)
		cout << rs[i] << endl;
}*/

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:14:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i = 0; i < w.size(); i++){
      |                 ~~^~~~~~~~~~
molecules.cpp:21:29: error: no match for 'operator>' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, int> >, std::pair<long long int, int> >::value_type' {aka 'std::pair<long long int, int>'} and 'int')
   21 |  if(tot_sum < l || new_w[0] > u)
In file included from /usr/include/c++/9/bits/stl_algobase.h:64,
                 from /usr/include/c++/9/vector:60,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_pair.h:467:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator>(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
  467 |     operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_pair.h:467:5: note:   template argument deduction/substitution failed:
molecules.cpp:21:31: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   21 |  if(tot_sum < l || new_w[0] > u)
      |                               ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/vector:60,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:343:5: note: candidate: 'template<class _Iterator> bool std::operator>(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
  343 |     operator>(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:343:5: note:   template argument deduction/substitution failed:
molecules.cpp:21:31: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, int> >, std::pair<long long int, int> >::value_type' {aka 'std::pair<long long int, int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
   21 |  if(tot_sum < l || new_w[0] > u)
      |                               ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/vector:60,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:381:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator>(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
  381 |     operator>(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:381:5: note:   template argument deduction/substitution failed:
molecules.cpp:21:31: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, int> >, std::pair<long long int, int> >::value_type' {aka 'std::pair<long long int, int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
   21 |  if(tot_sum < l || new_w[0] > u)
      |                               ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/vector:60,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:1187:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator>(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)'
 1187 |     operator>(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:1187:5: note:   template argument deduction/substitution failed:
molecules.cpp:21:31: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, int> >, std::pair<long long int, int> >::value_type' {aka 'std::pair<long long int, int>'} is not derived from 'const std::move_iterator<_IteratorL>'
   21 |  if(tot_sum < l || new_w[0] > u)
      |                               ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/vector:60,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:1193:5: note: candidate: 'template<class _Iterator> bool std::operator>(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)'
 1193 |     operator>(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:1193:5: note:   template argument deduction/substitution failed:
molecules.cpp:21:31: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, int> >, std::pair<long long int, int> >::value_type' {aka 'std::pair<long long int, int>'} is not derived from 'const std::move_iterator<_IteratorL>'
   21 |  if(tot_sum < l || new_w[0] > u)
      |                               ^
In file included from /usr/include/c++/9/vector:67,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1918:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator>(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)'
 1918 |     operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1918:5: note:   template argument deduction/substitution failed:
molecules.cpp:21:31: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, int> >, std::pair<long long int, int> >::value_type' {aka 'std::pair<long long int, int>'} is not derived from 'const std::vector<_Tp, _Alloc>'
   21 |  if(tot_sum < l || new_w[0] > u)
      |                               ^
molecules.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < new_w.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
molecules.cpp:29:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |      while(tot_sum_idx <= i || (tot_sum_idx < new_w.size() && tot_sum+currsum > u)){
      |                                 ~~~~~~~~~~~~^~~~~~~~~~~~~~
molecules.cpp:38:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    for(int x = tot_sum_idx; x < new_w.size(); x++)
      |                             ~~^~~~~~~~~~~~~~