제출 #1245624

#제출 시각아이디문제언어결과실행 시간메모리
1245624qs1식물 비교 (IOI20_plants)C++20
컴파일 에러
0 ms0 KiB
#include "plants.h"
#include<bits/stdc++.h>
#define lli long long int
using namespace std;

vector<lli>l;
lli x,y;

void init(int k, std::vector<int> r) {
	l=r;
	x=r.size();
	y=k;
}

int compare_plants(int a, int b) {
  lli n;
	int b1=1;
	if(a>b){
	  swap(a,b);
	  b1*=-1;
	}
	if(a+x-b<b-a){
	  n=a+x-b;
	  swap(a,b);
	  b1*=-1;
	}
	else{
	  n=b-a;
	}
	if(n>y){
	  return 0;
	}
	else if(n<=abs(l[b]-l[a])&&l[b]-l[a]>0){
	  return 1*b1;
	}
	else  if(n<=abs(l[b]-l[a])){
	  return -1*b1;
	}
	else{
	  return 0;
	}
}

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

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:10:11: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and 'std::vector<int>')
   10 |         l=r;
      |           ^
In file included from /usr/include/c++/11/vector:72,
                 from plants.h:1,
                 from plants.cpp:1:
/usr/include/c++/11/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::vector<long long int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/11/vector:67,
                 from plants.h:1,
                 from plants.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<long long int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::initializer_list<long long int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~