Submission #169535

#TimeUsernameProblemLanguageResultExecution timeMemory
169535LawlietRobots (IOI13_robots)C++17
Compilation error
0 ms0 KiB
#include "robots.h"
#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> pii;

const int MAXN = 1000010;

int N;
int qtdWeak;
int qtdSmall;

int size[MAXN];
int weight[MAXN];
int sizeLimit[MAXN];
int weightLimit[MAXN];

bool picked[MAXN];

vector< pii > sweepX;
vector< pii > sweepY;

bool cmp(pii a, pii b)
{
	int indA = a.second;
	int indB = b.second;

	if( a.first != b.first ) return a.first < b.first;
	return weight[indA] + size[indA] < weight[indB] + size[indB];
}

bool test(int k)
{
	int p = 0;

	set< pii > s;

	vector< int > aux;

	memset( picked , false , sizeof(picked) );

	for(int i = 1 ; i <= qtdSmall ; i++)
	{
		while( p < N && sweepX[p].first < sizeLimit[i] )
		{
			int ind = sweepX[ p++ ].second;
			s.insert( { -weight[ind] , ind } );
		}

		for(int j = 0 ; j < k ; j++)
		{
			if( s.empty() ) break;

			int ind = s.begin()->second;
			picked[ ind ] = true;

			s.erase( s.begin() );
		}
	}

	p = 0;

	for(int i = 1 ; i <= qtdWeak ; i++)
	{
		while( p < N && sweepY[p].first < weightLimit[i] )
		{
			int ind = sweepY[ p++ ].second;

			if( picked[ind] ) continue;
			aux.push_back( ind );
		}

		for(int j = 0 ; j < k ; j++)
		{
			if( aux.empty() ) break;

			picked[ aux.back() ] = true;
			aux.pop_back();
		}
	}

	for(int i = 1 ; i <= N ; i++)
		if( !picked[i] ) return false;

	return true;
}

int bs()
{
	int l = 0;
	int r = N;

	if( !test( r ) ) return -1;

	while( l < r )
	{
		int m = ( l + r )/2;

		if( test( m ) ) r = m;
		else l = m + 1;
	}

	return r;
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) 
{
	N = T;
	qtdWeak = A;
	qtdSmall = B;

	for(int i = 1 ; i <= N ; i++)
	{
		size[i] = S[i - 1];
		weight[i] = W[i - 1];

		sweepX.push_back( { size[i] , i } );
		sweepY.push_back( { weight[i] , i } );
	}

	for(int i = 1 ; i <= qtdWeak ; i++)
		weightLimit[i] = X[i - 1];

	for(int i = 1 ; i <= qtdSmall ; i++)
		sizeLimit[i] = Y[i - 1];

	sort( sweepX.begin() , sweepX.end() , cmp );
	sort( sweepY.begin() , sweepY.end() , cmp );
	sort( sizeLimit + 1 , sizeLimit + qtdSmall + 1 );
	sort( weightLimit + 1 , weightLimit + qtdWeak + 1 );

    return bs();
}

Compilation message (stderr)

robots.cpp: In function 'bool cmp(pii, pii)':
robots.cpp:29:24: error: reference to 'size' is ambiguous
  return weight[indA] + size[indA] < weight[indB] + size[indB];
                        ^~~~
robots.cpp:13:5: note: candidates are: int size [1000010]
 int size[MAXN];
     ^~~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from robots.cpp:2:
/usr/include/c++/7/bits/range_access.h:252:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])
     size(const _Tp (&/*__array*/)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:242:5: note:                 template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)
     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
     ^~~~
robots.cpp:29:52: error: reference to 'size' is ambiguous
  return weight[indA] + size[indA] < weight[indB] + size[indB];
                                                    ^~~~
robots.cpp:13:5: note: candidates are: int size [1000010]
 int size[MAXN];
     ^~~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from robots.cpp:2:
/usr/include/c++/7/bits/range_access.h:252:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])
     size(const _Tp (&/*__array*/)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:242:5: note:                 template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)
     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
     ^~~~
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:114:3: error: reference to 'size' is ambiguous
   size[i] = S[i - 1];
   ^~~~
robots.cpp:13:5: note: candidates are: int size [1000010]
 int size[MAXN];
     ^~~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from robots.cpp:2:
/usr/include/c++/7/bits/range_access.h:252:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])
     size(const _Tp (&/*__array*/)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:242:5: note:                 template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)
     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
     ^~~~
robots.cpp:117:23: error: reference to 'size' is ambiguous
   sweepX.push_back( { size[i] , i } );
                       ^~~~
robots.cpp:13:5: note: candidates are: int size [1000010]
 int size[MAXN];
     ^~~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from robots.cpp:2:
/usr/include/c++/7/bits/range_access.h:252:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])
     size(const _Tp (&/*__array*/)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:242:5: note:                 template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)
     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
     ^~~~
robots.cpp:117:37: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   sweepX.push_back( { size[i] , i } );
                                     ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/functional:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from robots.cpp:2:
/usr/include/c++/7/bits/stl_vector.h:939:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<int, int>&}'
/usr/include/c++/7/bits/stl_vector.h:953:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&& {aka std::pair<int, int>&&}'