답안 #63002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63002 2018-07-31T08:24:25 Z zetapi 쌀 창고 (IOI11_ricehub) C++14
100 / 100
27 ms 2264 KB
#include "ricehub.h"

#include <bits/stdc++.h>
using namespace std;

#define pb  push_back
#define mp  make_pair
#define ll	long long
#define itr ::iterator 

typedef pair<int,int>  pii;

const int MAX=1e5;

int N,arr[MAX];

int cal(int ind,ll left)
{
	int pre=ind-1,nxt=ind,res=0;
	while(left>=0 and (pre>=0 or nxt<N))
	{
		if(pre<0 or (nxt<N and arr[ind]-arr[pre]>arr[nxt]-arr[ind]))
		{
			if(arr[nxt]-arr[ind]>left)
				break;
			left-=arr[nxt]-arr[ind];
			res++;
			nxt++;
		}
		else
		{
			if(arr[ind]-arr[pre]>left)
				break;
			left-=arr[ind]-arr[pre];
			res++;
			pre--;
		}	
	}
	return res;
}

ll sum[MAX];

ll cal(int L,int R)
{
	ll mid=(L+R)/2,bt=mid-L+1,at=R-mid+1;
	return arr[mid]*bt-(sum[mid]-sum[L-1])+(sum[R]-sum[mid-1])-arr[mid]*at;
}

int besthub(int R, int L, int X[], long long B)
{
	int res=0,start=1;
	N=R;
	for(int A=0;A<N;A++)
		arr[A+1]=X[A];
	for(int A=1;A<=N;A++)
	{
		sum[A]=sum[A-1]+arr[A];
		while(start<A and cal(start,A)>B)
			++start;
		if(cal(start,A)<=B)
			res=max(res,A-start+1);
	}
	//cout<<cal(3,5)<<"\n";
	return res;
}

/*signed main()
{
	ios_base::sync_with_stdio(false);

	int X[]={1,2,10,12,14};
	cout<<besthub(5,20,X,6);	
	return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 3 ms 456 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 3 ms 640 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 640 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Correct 3 ms 640 KB Output is correct
21 Correct 2 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 2 ms 640 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 740 KB Output is correct
2 Correct 2 ms 740 KB Output is correct
3 Correct 3 ms 740 KB Output is correct
4 Correct 4 ms 740 KB Output is correct
5 Correct 2 ms 740 KB Output is correct
6 Correct 4 ms 740 KB Output is correct
7 Correct 2 ms 740 KB Output is correct
8 Correct 3 ms 740 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 3 ms 748 KB Output is correct
11 Correct 3 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 3 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 4 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 4 ms 748 KB Output is correct
23 Correct 4 ms 760 KB Output is correct
24 Correct 4 ms 760 KB Output is correct
25 Correct 3 ms 760 KB Output is correct
26 Correct 4 ms 760 KB Output is correct
27 Correct 4 ms 760 KB Output is correct
28 Correct 4 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 892 KB Output is correct
2 Correct 8 ms 892 KB Output is correct
3 Correct 22 ms 2172 KB Output is correct
4 Correct 25 ms 2172 KB Output is correct
5 Correct 10 ms 2172 KB Output is correct
6 Correct 11 ms 2172 KB Output is correct
7 Correct 19 ms 2264 KB Output is correct
8 Correct 21 ms 2264 KB Output is correct
9 Correct 10 ms 2264 KB Output is correct
10 Correct 12 ms 2264 KB Output is correct
11 Correct 22 ms 2264 KB Output is correct
12 Correct 27 ms 2264 KB Output is correct
13 Correct 16 ms 2264 KB Output is correct
14 Correct 11 ms 2264 KB Output is correct
15 Correct 16 ms 2264 KB Output is correct
16 Correct 17 ms 2264 KB Output is correct
17 Correct 23 ms 2264 KB Output is correct
18 Correct 18 ms 2264 KB Output is correct
19 Correct 21 ms 2264 KB Output is correct
20 Correct 20 ms 2264 KB Output is correct