답안 #285081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285081 2020-08-28T09:55:00 Z Bill_00 쌀 창고 (IOI11_ricehub) C++14
100 / 100
38 ms 2560 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int besthub(int R, int L, int a[], long long B)
{
	long long dp[100001];
	dp[0]=0;
	for(int i=1;i<R;i++){
		dp[i]=dp[i-1]+(ll)a[i]-(ll)a[0];
	}
	ll l=1,r=R;
	while(l!=r){
		ll mid=(l+r)>>1,flag=0;
		for(ll i=mid-1;i<(ll)R;i++){
			ll MID=(i*2+1-mid)>>1;
			ll left=i+1-mid;
			long long cost=dp[i]-dp[MID]-((i-MID)*((ll)a[MID]-(ll)a[0]))+(((ll)a[MID]-(ll)a[left])*(MID-left+1)-(dp[MID]-dp[left]-(MID-left)*((ll)a[left]-(ll)a[0])));
			if(cost<=B){
				flag++;
				break;
			}
		}
		if(flag==0) r=mid;
		else l=mid+1;
	}
	ll flag=0;
	for(ll i=l-1;i<(ll)R;i++){
		ll MID=(i*2+1-l)>>1;
		ll left=i+1-l;
		long long cost=dp[i]-dp[MID]-((i-MID)*((ll)a[MID]-(ll)a[0]))+(((ll)a[MID]-(ll)a[left])*(MID-left+1)-(dp[MID]-dp[left]-(MID-left)*((ll)a[left]-(ll)a[0])));
		if(cost<=B){
			flag++;
			break;
		}
	}
	if(flag>0) return l;
	return l-1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 360 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 19 ms 1792 KB Output is correct
4 Correct 18 ms 2560 KB Output is correct
5 Correct 18 ms 1280 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 27 ms 2296 KB Output is correct
8 Correct 33 ms 2300 KB Output is correct
9 Correct 9 ms 1152 KB Output is correct
10 Correct 17 ms 1152 KB Output is correct
11 Correct 19 ms 2560 KB Output is correct
12 Correct 38 ms 2552 KB Output is correct
13 Correct 10 ms 1280 KB Output is correct
14 Correct 23 ms 1272 KB Output is correct
15 Correct 14 ms 1920 KB Output is correct
16 Correct 16 ms 1920 KB Output is correct
17 Correct 17 ms 2304 KB Output is correct
18 Correct 17 ms 2340 KB Output is correct
19 Correct 18 ms 2432 KB Output is correct
20 Correct 18 ms 2432 KB Output is correct