답안 #61763

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61763 2018-07-26T15:30:37 Z CaQtiml 쌀 창고 (IOI11_ricehub) C++14
컴파일 오류
0 ms 0 KB
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
#include <cassert>
#include <numeric>

#define NMAX 100010
#define INF 1e18

using namespace std;
typedef long long lli;

lli prev[NMAX];
lli next[NMAX];
lli pos[NMAX];

int N;
lli B;

lli min_cost(int k){
	lli mcost,cost;
	int i,p,n;

	mcost = INF;

	p = (k-1)/2;
	n = k/2;

	prev[0] = 0;
	for(i = 1; i < N; ++i){
		prev[i] = prev[i-1] + (pos[i]-pos[i-1])*1LL*min(i,p);
		if(i > p) prev[i] -= (pos[i-1]-pos[i-p-1]);
	}

	next[N-1]  =0;
	for(i = N-2; i >= 0; --i){
		next[i] = next[i+1]+(pos[i+1]-pos[i])*1LL*min(N-i-1,n);
		if(i+n < N-1) next[i] -= (pos[i+n+1]-pos[i+1]);
	}

	for(i = 0; i < N; ++i){
		if(i-p >= 0 && i+n < N){
			cost = next[i]+prev[i];
			mcost = min(cost,mcost);
		}
	}
//	assert(mcost >= 0);
//	cout << mcost << ' ' << k<< endl;
	return mcost;
}

int search(){
	int low,high,mid;

	low = 1;
	high = N;

	while(low < high){
		mid = (high+low+1)/2;

		if(min_cost(mid) <= B){
			low = mid;
		}else{
			high =  mid-1;
		}
	}

	return low;
}

int besthub(int R, int L, int *x, lli b){
	int i;

	N = R;
	B = b;
	for(i = 0; i < N; ++i){
		pos[i] = x[i];
	}

	return search();
}

Compilation message

ricehub.cpp: In function 'lli min_cost(int)':
ricehub.cpp:31:2: error: reference to 'prev' is ambiguous
  prev[0] = 0;
  ^~~~
ricehub.cpp:15:5: note: candidates are: lli prev [100010]
 lli prev[NMAX];
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/algorithm:61,
                 from ricehub.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:220:5: note:                 template<class _BidirectionalIterator> _BidirectionalIterator std::prev(_BidirectionalIterator, typename std::iterator_traits<_Iter>::difference_type)
     prev(_BidirectionalIterator __x, typename
     ^~~~
ricehub.cpp:33:3: error: reference to 'prev' is ambiguous
   prev[i] = prev[i-1] + (pos[i]-pos[i-1])*1LL*min(i,p);
   ^~~~
ricehub.cpp:15:5: note: candidates are: lli prev [100010]
 lli prev[NMAX];
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/algorithm:61,
                 from ricehub.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:220:5: note:                 template<class _BidirectionalIterator> _BidirectionalIterator std::prev(_BidirectionalIterator, typename std::iterator_traits<_Iter>::difference_type)
     prev(_BidirectionalIterator __x, typename
     ^~~~
ricehub.cpp:33:13: error: reference to 'prev' is ambiguous
   prev[i] = prev[i-1] + (pos[i]-pos[i-1])*1LL*min(i,p);
             ^~~~
ricehub.cpp:15:5: note: candidates are: lli prev [100010]
 lli prev[NMAX];
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/algorithm:61,
                 from ricehub.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:220:5: note:                 template<class _BidirectionalIterator> _BidirectionalIterator std::prev(_BidirectionalIterator, typename std::iterator_traits<_Iter>::difference_type)
     prev(_BidirectionalIterator __x, typename
     ^~~~
ricehub.cpp:34:13: error: reference to 'prev' is ambiguous
   if(i > p) prev[i] -= (pos[i-1]-pos[i-p-1]);
             ^~~~
ricehub.cpp:15:5: note: candidates are: lli prev [100010]
 lli prev[NMAX];
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/algorithm:61,
                 from ricehub.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:220:5: note:                 template<class _BidirectionalIterator> _BidirectionalIterator std::prev(_BidirectionalIterator, typename std::iterator_traits<_Iter>::difference_type)
     prev(_BidirectionalIterator __x, typename
     ^~~~
ricehub.cpp:37:2: error: reference to 'next' is ambiguous
  next[N-1]  =0;
  ^~~~
ricehub.cpp:16:5: note: candidates are: lli next [100010]
 lli next[NMAX];
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/algorithm:61,
                 from ricehub.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
ricehub.cpp:39:3: error: reference to 'next' is ambiguous
   next[i] = next[i+1]+(pos[i+1]-pos[i])*1LL*min(N-i-1,n);
   ^~~~
ricehub.cpp:16:5: note: candidates are: lli next [100010]
 lli next[NMAX];
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/algorithm:61,
                 from ricehub.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
ricehub.cpp:39:13: error: reference to 'next' is ambiguous
   next[i] = next[i+1]+(pos[i+1]-pos[i])*1LL*min(N-i-1,n);
             ^~~~
ricehub.cpp:16:5: note: candidates are: lli next [100010]
 lli next[NMAX];
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/algorithm:61,
                 from ricehub.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
ricehub.cpp:40:17: error: reference to 'next' is ambiguous
   if(i+n < N-1) next[i] -= (pos[i+n+1]-pos[i+1]);
                 ^~~~
ricehub.cpp:16:5: note: candidates are: lli next [100010]
 lli next[NMAX];
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/algorithm:61,
                 from ricehub.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
ricehub.cpp:45:11: error: reference to 'next' is ambiguous
    cost = next[i]+prev[i];
           ^~~~
ricehub.cpp:16:5: note: candidates are: lli next [100010]
 lli next[NMAX];
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/algorithm:61,
                 from ricehub.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
ricehub.cpp:45:19: error: reference to 'prev' is ambiguous
    cost = next[i]+prev[i];
                   ^~~~
ricehub.cpp:15:5: note: candidates are: lli prev [100010]
 lli prev[NMAX];
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/algorithm:61,
                 from ricehub.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:220:5: note:                 template<class _BidirectionalIterator> _BidirectionalIterator std::prev(_BidirectionalIterator, typename std::iterator_traits<_Iter>::difference_type)
     prev(_BidirectionalIterator __x, typename
     ^~~~