Submission #369768

# Submission time Handle Problem Language Result Execution time Memory
369768 2021-02-22T11:45:16 Z MilosMilutinovic Comparing Plants (IOI20_plants) C++14
Compilation error
0 ms 0 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;

int n, k;
vector<int> a, sum;
int compare_plants(int x, int y) {
	if(sum[x]==sum[y-1])
		return 1;
	if(sum[n-1]-sum[y]==n-y-1&&(x==0||sum[x-1]==x))
		return 1;
	swap(x,y);
	if(sum[x]==sum[y-1])
		return -1;
	if(sum[n-1]-sum[y]==n-y-1&&(x==0||sum[x-1]==x))
		return -1;
	return 0;
}

void init(int K, vector<int> r) {
	n=(int)r.size(), k=K, a=r, sum=partial_sum(a.begin(), a.end(), a.begin());
}

/*int main() {
	init(2, {0, 1, 0, 1});
	cout << compare_plants(1, 3);
	return 0;
}*/

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:21:74: error: no match for 'operator=' (operand types are 'std::vector<int>' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >')
   21 |  n=(int)r.size(), k=K, a=r, sum=partial_sum(a.begin(), a.end(), a.begin());
      |                                                                          ^
In file included from /usr/include/c++/9/vector:72,
                 from plants.h:1,
                 from plants.cpp:1:
/usr/include/c++/9/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/9/vector:67,
                 from plants.h:1,
                 from plants.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:706:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:706:26: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'std::vector<int>&&'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:727:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  727 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:727:46: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'std::initializer_list<int>'
  727 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~