Submission #832776

# Submission time Handle Problem Language Result Execution time Memory
832776 2023-08-21T14:52:08 Z vqpahmad Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "candies.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 1e6 + 15;
const ll inf = 1e18;


vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
	int n = c.size();
	vector<int> s(n);
	int q = sz(v);
	int sub1 = (n<=2000&&q<=2000);
	int sub2 = 1;
	int sub3 = 1;
	int sub4 = 1;
	for (auto it : v){
		if (it < 0) sub2 = 0;
	}
	for (int i=1;i<n;i++){
		sub3 &= c[i]==c[i-1];
	}
	for (int i=0;i<q;i++){
		sub4 &= l[i]==0&&r[i]==n-1;
	}
	if (sub1){
		for (int i=0;i<q;i++){
			for (int k=l[i];k<=r[i];k++){
				s[k] += v[i];
				s[k] = max(0,s[k]);
				s[k] = min(s[k],c[k]);
			}
		}
	}
	else if (sub2){
		vector<ll> prf(n+1,0);
		for (int i=0;i<q;i++){
			prf[l[i]]+=v[i];
			prf[r[i]+1]-=v[i];
		}
		for (int i=1;i<=n;i++){
			prf[i] += prf[i-1];
		}
		for (int i=0;i<n;i++){
			prf[i] = min(prf[i],c[i]);
			s[i] = prf[i];
		}
	}
	else if (sub3){

	}
	else if (sub4){
		vector<ll> a(q);
		for (int i=0;i<q;i++){
			a[i] = v[i];
			if (i) a[i] += a[i-1];
		}
		vector<ll> mn(q+1), mx(q+1);
		mn[q] = inf, mx[q] = -inf;
		for (int i=n-1;i>=0;i--){
			mn[i] = min(a[i],mn[i+1]);
			mx[i] = max(a[i],mx[i+1]);
		}
		for (int i=0;i<n;i++){
			int lo=-1,hi=q;// lo + 1
			while (hi-lo > 1){
				int mi = (lo+hi)/2;
				if (mx[mi]-mn[mi] >= c[i]) hi = mi;
				else lo = mi;
			}
			if (hi==n){
				s[i] = a.back();
			}
			else {
				if (a[hi]==mx[hi]){// hit zero
					s[i] = mx[hi]-mn[hi];
				}
				else {
					s[i] = c[i] - (mx[hi]-mn[hi]);
				}
			}
		}
	}
	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:53:28: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   53 |    prf[i] = min(prf[i],c[i]);
      |                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
candies.cpp:53:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   53 |    prf[i] = min(prf[i],c[i]);
      |                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
candies.cpp:53:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   53 |    prf[i] = min(prf[i],c[i]);
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
candies.cpp:53:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   53 |    prf[i] = min(prf[i],c[i]);
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
candies.cpp:53:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   53 |    prf[i] = min(prf[i],c[i]);
      |                            ^