Submission #530212

# Submission time Handle Problem Language Result Execution time Memory
530212 2022-02-24T19:46:21 Z Icebear16 Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include "candies.h"
#include <vector>

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) {
    int n=c.size();
    int q=l.size();
    std::vector<int> s(n,0);
    bool flag=true;
    for(int i=0;i<q;i++){
    	if(v[i]<0){
    		flag=false;
    		break;
		}
	}
	if(flag==false){
		for(int j=0;j<q;j++){
			for(int i=l;i<=r;i++){
				if(v[j]>=0){
					s[i]=max(c[i],s[i]+v[j]);
				}else{
					s[i]=max(c[i],s[i]+v[j]);
				}
			}
		}
	}else{
		s.push_back(0);
		for(int j=0;j<q;j++){
			s[l[j]]+=v[j];
			s[r[j+1]]-=v[j];
		}
		for(int i=1;i<=n;i++){
			s[i]+=s[i-1];
		}
		reverse(s.begin(),s.end());
		s.pop_back();
		reverse(s.begin(),s.end());
	}
    return s;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:17:14: error: cannot convert 'std::vector<int>' to 'int' in initialization
   17 |    for(int i=l;i<=r;i++){
      |              ^
      |              |
      |              std::vector<int>
candies.cpp:17:17: error: no match for 'operator<=' (operand types are 'int' and 'std::vector<int>')
   17 |    for(int i=l;i<=r;i++){
      |                ~^~~
      |                |  |
      |                |  std::vector<int>
      |                int
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:508:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
  508 |     operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:508:5: note:   template argument deduction/substitution failed:
candies.cpp:17:19: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   17 |    for(int i=l;i<=r;i++){
      |                   ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:384:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
  384 |     operator<=(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:384:5: note:   template argument deduction/substitution failed:
candies.cpp:17:19: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   17 |    for(int i=l;i<=r;i++){
      |                   ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:422:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
  422 |     operator<=(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:422:5: note:   template argument deduction/substitution failed:
candies.cpp:17:19: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   17 |    for(int i=l;i<=r;i++){
      |                   ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1460:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)'
 1460 |     operator<=(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1460:5: note:   template argument deduction/substitution failed:
candies.cpp:17:19: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
   17 |    for(int i=l;i<=r;i++){
      |                   ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1513:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)'
 1513 |     operator<=(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1513:5: note:   template argument deduction/substitution failed:
candies.cpp:17:19: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
   17 |    for(int i=l;i<=r;i++){
      |                   ^
In file included from /usr/include/c++/10/vector:67,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1949:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator<=(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)'
 1949 |     operator<=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1949:5: note:   template argument deduction/substitution failed:
candies.cpp:17:19: note:   mismatched types 'const std::vector<_Tp, _Alloc>' and 'int'
   17 |    for(int i=l;i<=r;i++){
      |                   ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1126: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>&)'
 1126 |     operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1126:5: note:   template argument deduction/substitution failed:
candies.cpp:17:19: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' and 'int'
   17 |    for(int i=l;i<=r;i++){
      |                   ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1134: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>&)'
 1134 |     operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1134:5: note:   template argument deduction/substitution failed:
candies.cpp:17:19: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' and 'int'
   17 |    for(int i=l;i<=r;i++){
      |                   ^
candies.cpp:19:11: error: 'max' was not declared in this scope; did you mean 'std::max'?
   19 |      s[i]=max(c[i],s[i]+v[j]);
      |           ^~~
      |           std::max
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: 'std::max' declared here
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
candies.cpp:21:11: error: 'max' was not declared in this scope; did you mean 'std::max'?
   21 |      s[i]=max(c[i],s[i]+v[j]);
      |           ^~~
      |           std::max
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: 'std::max' declared here
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
candies.cpp:34:3: error: 'reverse' was not declared in this scope
   34 |   reverse(s.begin(),s.end());
      |   ^~~~~~~